我有以下代码,但它在以下位置给出了运行时错误“438”:
wdRng.PrintOut
如果我将其更改为
MsgBox wdRng
它确实为MsgBox提供了选择。所以PrintOut方法有问题。有人有什么建议吗?
Dim i As Long, wdApp As Object, wdDoc As Object, wdRng As Object
Set wdApp = CreateObject("Word.Application")
With wdApp
.Visible = True
For i = 1 To 200
Set wdDoc = .Documents.Open("\\path\Machine\Results" & i & ".doc", False, True, False)
With wdDoc
Set wdRng = .Range(0, 0)
With .Range
With .Find
.Text = "END"
.Forward = True
.MatchWholeWord = True
.MatchCase = True
.Execute
End With
If .Find.found = True Then
wdRng.End = .Duplicate.Start
wdRng.PrintOut
End If
End With
.Close False
End With
Next
.Quit
End With
Set wdRng = Nothing: Set wdDoc = Nothing: Set wdApp = Nothing
答案 0 :(得分:0)
MS Word中的.Printout
没有Range object
方法。
尝试使用此逻辑而不是wdRng.Printout
:
wdRng.Select
wdApp.PrintOut ,,WdPrintOutRange.wdPrintSelection
或 wdDoc.PrintOut ,, WdPrintOutRange.wdPrintSelection
编辑 - 尝试.PrintOut
的任何一行:
wdDoc.PrintOut , , 1
wdApp.PrintOut ,, 1