运行时错误424 要求对象 。老问题,但我有点自己的疑问_涉及到赋值
关于 “运行时错误424 要求对象 ”这个可能是老问题了 。我搜了一下网上的解决 。没有解决关于我的疑问的。
-------- 下面这个例子 是word 帮助里的 , 当然,直接运行 ,肯定是有问题的 begin -----------------
Sub SelectRange()
Dim rngParagraph As Range
Set rngParagraph = ActiveDocument.Paragraphs(2).Range
rngParagraph.SetRange Start:=rngParagraph.Start, _
End:=ActiveDocument.Paragraphs(3).Range.End
rngParagraph.Select
Selection.Font.Italic = True
End Sub
-------- 下面这个例子 是word 帮助里的 当然,直接运行 ,肯定是有问题的 end -----------------
自己试了一下 ,代码如下:
Sub Test()
Dim objWordApp As Object
Dim objWord As Object
'Dim objWord As Word.Document
Dim myRange As Object
Dim mySelection As Word.Selection
' Dim mySelection As Object
' Dim mySelection As Selection
' Dim rngParagraph As Range
Dim rngParagraph As Object
Set objWordApp = CreateObject("Word.Application")
Set objWord = objWordApp.Documents.Open("d:\测试文件.doc")
Set rngParagraph = objWord.Paragraphs(1).Range
rngParagraph.SetRange Start:=rngParagraph.Start, _
End:=objWord.Paragraphs(2).Range.End
Set mySelection = rngParagraph.Select ' 运行到这里错误 ,错误为 “运行时错误424 要求对象”
'rngParagraph.Select 返回的不是selection 对象吗 ?为什么赋值出现问题,我要怎么声明才对了
' rang对象 要怎么样的方式 ,才可以转化为SELECTION 对象啊 ?
'以下三种方式都试了不可以
' Dim mySelection As Word.Selection
' Dim mySelection As Object
' Dim mySelection As Selection
mySelection.Font.Size = 25
objWord.Save
objWord.Close
objWordApp.Quit
End Sub
[解决办法]