excel 操作 world

时间:2016-06-02 16:09:27
【文件属性】:
文件名称:excel 操作 world
文件大小:17KB
文件格式:DOCX
更新时间:2016-06-02 16:09:27
excel 操作 world 实用vbs:操作word文档,实现输入自动化 '注意需要安装微软的WORD才可以正常使用 welText="本脚本运行后将在WORD种显示一些计算机的信息" MsgBox welText '定义Word.application变量 Dim ObjWD Dim ObjDOC Dim counti Set WshNetwork=CreateObject("WScript.Network") '启动Word Set ObjWD=CreateObject("Word.application") '设置Word为可视 ObjWD.Visible=True '增加一个文档 ObjWD.Documents.Add Set ObjDOC=ObjWD.ActiveDocuments '设置格式为剧中对齐 ObjWD.selection.ParagraphFormat.Alignment=wdAlignParagraphCenter ObjDOC.Range 0,0 ObjWD.selection.TypeText "计算机信息一览表"+Chr(13) '增加一张四行二列的表格 ObjDOC.Tables.Add ObjWD.selection.Range,4,2 ObjWD.selection.TypeText "类别" ObjWD.selection.Moveright ObjWD.selection.TypeText "值" '循环填写表格内容 For counti=1 To 3 ObjWD.selection.MoveDown ObjWD.selection.MoveLeft Select Case counti Case 1 ObjWD.selection.TypeText "域名" ObjWD.selection.MoveRight ObjWD.selection.TypeText WshNetwork.UserDomain Case 2 ObjWD.selection.TypeText "计算机名" ObjWD.selection.MoveRight ObjWD.selection.TypeText WshNetwork.ComputerName Case 3 ObjWD.selection.TypeText "用户名" ObjWD.selection.MoveRight ObjWD.selection.TypeText WshNetwork.UserName End Select Next '将WORD窗口最大化 ObjWD.WindowState=1 '选中全部文档 ObjWD.selection.WholeStory '设置字体 ObjWD.selection.font.Name="宋体" '设置字号 ObjWD.selection.font.Size=14 '设置对齐方式为居中 ObjWD.selection.ParagraphFormat.Alignment=1 '取消全部选中 ObjWD.selection.MoveDown

网友评论