尽管谷歌的搜索量很大,但我还是想不出这到底是怎么回事。我是不是还漏掉了推荐信什么的?如果你能看到错误的所在,我将永远感激你!
参考文献:
变量:
Public appWord As Word.Application
Public sapmWord As Word.Document
Dim asNimi As String 'in this current sub
代码:
On Error Resume Next
Set appWord = GetObject(, "Word.Application")
If Err <> 0 Then
Set appWord = CreateObject("Word.Application")
End If
On Error GoTo 0
appWord.Visible = True
Set sapmWord = appWord.documents.Open("C:\ThisIsWorking\andDocOpens.docx")
'sapmWord.Activate 'doesn't make a difference
With sapmWord
Selection.EndKey Unit = wdStory 'this line is first line to give an error. With or without a dot in the beginning of line.
Selection.TypeText Text:=asNimi 'this line too, if previous is commented
'...and so on!
End With
sapmWord.Close savechanges:=True
Set appWord = Nothing
Set sapmWord = Nothing
发布于 2018-06-26 08:14:33
sapmWord
是一个word文档。word文档没有
selection
方法。应用程序对象这个词有它,所以你可能是指(是的,你需要'.')
With appWord
.Selection.EndKey Unit:= wdStory