vb6中word编程总结 - 中国WEB开发者网络 (http://www.webasp.net) -- 技术教程 (http://www.webasp.net/article/) --- vb6中word编程总结 (http://www.webasp.net/article/13/12080.htm) |
| -- 作者:未知 -- 发布日期: 2004-07-31 |
| 1,在project\references 中加入microsoft word 9.0 object library
2, 启动word Dim wApp As Word.Application Set wApp = New Word.Application wApp.Visible = True 关闭word wApp.Quit Set wApp = Nothing 3, 打开文件 Set wDoc = Documents.Add (新建) ActiveDocument.SaveAs Text1.Text (保存) Set wDoc = Documents.Open(FileName:=Text1.Text) (打开指定文件) 以上的Documents 和 ActiveDocument 均是word object 中的已实例化了的对象,即不用set obj=new obj即可以使用的对象. 就像vb中的app、debug、err等对象, 文件打开之后,获取光标所在位置mySelection即可给文件添加各种数据(文本,图像,表格等等,) 4,插入文本 Dim mySelection As Word.Selection Set mySelection = Documents.Application.Selection '注意上面的这两行代码,只要有这两行代码,就可以使用所有的word中的宏操作。以下的代码就是从宏中拷过来的。 With mySelection .InsertAfter Text1.Text & vbCrLf .Font.Name = "楷体_GB2312" .Font.Size = 16 .ParagraphFormat.Alignment = 1 End With '这里有必要提到宏(macro)在word编程的重要性,几乎所有的word操作,只要你能够通过word可以实现,就可以编程实现 5,插入图像 Documents.Application.Selection.InlineShapes.AddPicture text1.text 6,插入表格 因为excel中处理表格的能力要比word的处理能力要强,所以可以在excel中生成了表格之后再复制到word当中 |
| webasp.net |