请参考: Option Explicit Sub Example() '请在EXCEL VBE\工具\引用中勾选对于Microsoft Word 11.0(视版本)Object Library 的引用 Dim myWord As Word.Application Dim myDoc As Word.Document On Error Resume Next '忽略错误 Set myWord = GetObject(, "Word.Application") '返回对于Word程序的引用 If Err.Number <> 0 Then '如果没有打开的Word程序,则出错 Err.Clear '清除错误号 Set myWord = CreateObject("Word.Application") '创建一个对于Word程序的引用 End If With myWord Set myDoc = .Documents.Add '新建一个文档 With myDoc With .PageSetup '页面设置 .LeftMargin = myWord.CentimetersToPoints(2.54) '左页边距为2.54CM .RightMargin = myWord.CentimetersToPoints(2.54) '右页边距为2.54CM .TopMargin = myWord.CentimetersToPoints(3.17) '上页边距为3.17CM .BottomMargin = myWord.CentimetersToPoints(3.17) '下页边距为3.17 End With End With .Visible = True '使Word 程序可见 End With End Sub
|