尽管进行了大量的谷歌搜索,但我无法弄清楚这有什么问题。我仍然错过引用或其他什么吗?如果您能看到错误所在,我将永远感激不尽!
引用:
变量:
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
最佳答案
sapmWord
是word文档。 Word 文档没有 selection
方法。 Word 应用程序对象有它,所以可能你的意思是(是的,你需要'.')
With appWord
.Selection.EndKey Unit:= wdStory
.Selection.TypeText Text:=asNimi
'...and so on!
End With
关于excel - VBA:使用 Excel 编辑 Word 文档会出现运行时错误 438:对象不支持此属性或方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51037697/