尽管谷歌的搜索量很大,但我还是想不出这到底是怎么回事。我是不是还漏掉了推荐信什么的?如果你能看到错误的所在,我将永远感激你!
参考文献:
变量:
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
.Selection.TypeText Text:=asNimi
'...and so on!
End With发布于 2020-06-10 19:47:32
您必须将sapmWord.Close savechanges:=True改为appWord.quit savechanges:=True
发布于 2018-06-26 08:10:24
若要使用With,必须使用.引用成员
With sapmWord
.Selection.EndKey Unit = wdStory
.Selection.TypeText Text:=asNimi
End Withhttps://stackoverflow.com/questions/51037697
复制相似问题