vb6中word编程总结

<script type="text/javascript"> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
<script type="text/javascript"> </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>

1,在projecteferences 中加入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当中

<script type="text/javascript"> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
<script type="text/javascript"> </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值