|
原帖由 njwyt 于 2011-7-7 09:52 发表
谢谢你。按照你的思路,我将所有相关的文字描述全部按照对应的数字进行了替换,结果就可以运行了。而且也可以将内容直接先复制到了第一页。但就是步骤有些烦琐。以下的两个问题,请有这方面经验的人是否可以帮忙看看 ...
我做了一个简单的例子,来帮你说明解决问题的方法.
Sub Begin()
Dim i As Integer, C As Integer, boo_Word As Boolean
C = Application.VBE.ActiveVBProject.References.Count
For i = 1 To C
If Application.VBE.ActiveVBProject.References(i).Name = "Word" Then
boo_Word = True '记录是否已经添加引用Microsoft Word Object Library
Exit For
End If
Next
If Not boo_Word Then
'如果没有引用Microsoft Word Object Library,则添加之
Application.VBE.ActiveVBProject.References.AddFromGuid "{00020905-0000-0000-C000-000000000046}", 8, 4
End If
CWord
End Sub
Sub CWord()
Dim appWD As New Word.Application
appWD.Visible = True
appWD.Documents.Add
'以下设置页眉
With appWD.ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary)
.Range.Text = "No." & ActiveDocument.Name & " " & _
Format(Date, "mmm. dd, yyyy") & " Page "
.Range.Fields.Add .Range.Characters.Last, wdFieldPage
.Range.InsertAfter " of page "
.Range.Fields.Add .Range.Characters.Last, wdFieldNumPages
End With
End Sub |
|