Application.Workbooks.Open FileName

paul2002 2006-09-20 02:18:57
在VBA中用Application.Workbooks.Open FileName 可以打开excel文件,但是当EXCEL在IE中in-place打开时,该方法失效,请问怎样解决?
3X
...全文
375 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
m00ners 2006-12-01
  • 打赏
  • 举报
回复
不懂。帮顶
wada0880 2006-11-10
  • 打赏
  • 举报
回复
不明白
Dunzip 2006-11-08
  • 打赏
  • 举报
回复
关注
jam021 2006-11-08
  • 打赏
  • 举报
回复
没看明白,关注中
hhjjhjhj 2006-09-21
  • 打赏
  • 举报
回复
Dim xlapp As New Application
xlapp.Visible = True
xlapp.Workbooks.Open FileName



======================

欢迎光临“OFFICE论坛”http://office.9zp.com
happy_sea 2006-09-21
  • 打赏
  • 举报
回复
不会,帮顶!
paul2002 2006-09-21
  • 打赏
  • 举报
回复
没人气啊
//About my self excel control ..... study data // for your information... unit toxls5butt; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Excel2000, OleServer; type TForm1 = class(TForm) Button1: TButton; Button2: TButton; Button3: TButton; Button4: TButton; CheckBox1: TCheckBox; Button5: TButton; SaveDialog1: TSaveDialog; OpenDialog1: TOpenDialog; // ExcelWorksheet1: TExcelWorksheet; // ExcelOLEObject1: TExcelOLEObject; // ExcelWorkbook1: TExcelWorkbook; // ExcelApplication1: TExcelApplication; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button3Click(Sender: TObject); procedure Button4Click(Sender: TObject); private v:variant; sheet:variant; { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation { *.dfm} uses comobj; procedure TForm1.Button1Click(Sender: TObject); begin try V:=createoleobject(‘excel.application‘); v.visible:=checkbox1.Checked; v.workbooks.add; v.workbooks[1].worksheets[1].name:=‘good‘; sheet:=v.workbooks[1].worksheets[1]; sheet.cells[3,1]:=‘31‘; sheet.cells[2,1]:=‘21‘; sheet.cells[1.5]:=‘15‘; sheet.cells[2,2]:=‘22‘; v.workbooks[1].worksheets[2].name:=‘love‘; sheet:=v.workbooks[1].worksheets[2]; sheet.cells[3,4]:=‘34hello‘; // sheet:=v.workbooks[1].worksheets[‘helloaaa‘]; except showmessage(‘excel init load error, not excel or other error!‘); v.displayalerts:=false; v.quit; exit; end; application.Restore; application.BringToFront; end; procedure TForm1.Button2Click(Sender: TObject); begin if opendialog1.Execute then begin try V:=createoleobject(‘excel.application‘); v.visible:=checkbox1.Checked; v.workbooks.open(opendialog1.FileName); except showmessage(‘excel init error, not excel or other error, try again‘); v.displayalerts:=false; v.quit; exit; end; application.Restore; application.BringToFront; end; end; procedure TForm1.Button3Click(Sender: TObject); begin try if not varisempty(v) then begin v.DisplayAlert:=true; v.workbooks[1].close(true,‘c:untitled.xls‘); v.workbooks[1].close(true,‘*.xls‘); v.quit; end; finally close; end; end; procedure TForm1.Button4Click(Sender: TObject); begin if opendialog1.Execute then begin try v:=createoleObject(‘excel.application‘); v.visible:=checkbox1.Checked; v.workbooks.open(opendialog1.FileName); sheet:=v.workbooks[1].worksheet[1]; sheet.pagesetup.printtitlerows:=‘$1:$3‘; //page head sheet.pagesetup.printtitlecolumns:=‘‘; sheet.pagesetup.leftfooter:=‘Noted: PageHead‘+‘sum total&N page ‘+‘--No.&Page‘; //pagehead sheet.pagesetup.leftmargin:=30; //偞离?擒 Sheet.PageSetup.RightMargin := 30; Sheet.PageSetup.TopMargin := 30; Sheet.PageSetup.BottomMargin := 50; Sheet.PageSetup.PrintQuality := 300; //賤昴僅(跦?荂桶復隅) Sheet.PageSetup.CenterHorizontally := True;//岆瘁阨懈笢 Sheet.PageSetup.CenterVertically := True; //岆瘁晶眻懈笢 Sheet.PageSetup.Orientation := 2; //砃蹈荂 Sheet.PageSetup.Draft := False; //準翌詨耀宒 Sheet.PageSetup.FirstPageNumber := xlAutomatic; Sheet.PageSetup.BlackAndWhite := false; //窪啞詨 Sheet.PageSetup.Zoom := 100; //窺溫 sheet.PrintPreView; //蹈荂蕼罜 except Showmessage(‘initiale error ㄛnot Excelㄛor other error ˙try again!‘); v.DisplayAlerts := false; v.Quit; // finally exit; end; end; end; end.
private void Save2Excel() { //string file = "F:\\11\\ck.xlsx"; //string path = "F:\\11\\excel\\"; string time = DateTime.Now.ToString("yyyyMMdd"); string file = System.Windows.Forms.Application.StartupPath + "\\ck.xlsx"; string path = System.Windows.Forms.Application.StartupPath + "\\excel\\"; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } string saveName1 = path + "_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xlsx"; excel = new CCExcel(file,saveName1); excel.Exceldata(); } private void textBox1_TextChanged(object sender, EventArgs e) { Form1.name = textBox1.Text.ToString(); } private void Form1_Load(object sender, EventArgs e) { comboBox1.Text = 11.ToString(); comboBox2.Text = 100.ToString(); } private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { Form1.comB1 = comboBox1.Text.ToString(); } private void comboBox2_SelectedIndexChanged(object sender, EventArgs e) { Form1.comB2 = comboBox2.Text.ToString(); } } public class CCExcel { public Excel.Application appExcel; public Excel.Workbooks wbs; public Excel.Workbook wb; public Excel.Worksheets wss; public Excel.Worksheet ws; private string fileName; private string saveName; public CCExcel(string fileName,string saveName) { // //TODO: 在此处添加构造函数逻辑 // this.fileName = fileName; this.saveName = saveName; } public void Exceldata() { Create(); //Open(fileName); Data2Excel(); Save(saveName); //Save(wb,saveName); //appExcel.ActiveWorkbook.SaveCopyAs(fileName); //判断当前激活的表,并保存这个表。否则,保存时会弹出“是否保存Sheet1.xlsx”的对话框 wb.Close(Type.Missing, Type.Missing, Type.Missing); wbs.Close(); appExcel.Quit(); wb = null; wbs = null; appExcel = null; GC.Collect(); } private void Create()//创建一个Excel对象 { appExcel = new Excel.Application(); wbs = appExcel.Workbooks; wb = wbs.Add(true); //ws = (Excel.Worksheet)wb.ActiveSheet;//这是一个只读sheets集合 //Excel.Worksheet worksheet = wb.ActiveSheet as Excel.Worksheet;//这也是一个只读sheets集合 //Excel.Worksheet ws = (Worksheet)wb.Worksheets[1];//创建工作页sheet单页 ws = wb.Worksheets[1] as Worksheet; //第一个sheet页 ws.Name = "ck"; //这里修改sheet名称 } public void Open(string fileName) { appExcel = new Excel.Application(); wbs = appExcel.Workbooks; wb = wbs.Add(fileName); wb = wbs.Open(fileName,Type.Missing,Type.Missing,Type.Missing,Type.Missing, Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing, Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing); }

2,503

社区成员

发帖
与我相关
我的任务
社区描述
VBA(Visual Basic for Applications)是Visual Basic的一种宏语言,是在其桌面应用程序中执行通用的自动化(OLE)任务的编程语言。
社区管理员
  • VBA
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧