0
打印選定頁面我想從Excel VBA中打印Word文檔選定頁面,頁碼將從輸入消息框中獲得。我得到運行時錯誤5148.運行時錯誤5148 - 從代碼
請在此幫助我。
Dim directory As String, fileName As String, ans As String, i As Integer
Dim objWord As Object
Dim intpage As Integer, intcopies As Integer
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
' path to the folder
directory = "E:\print\"
fileName = Dir(directory & "*.doc*") ' Open Multiple Word Docs Both .doc and .docx
Do While fileName <> ""
objWord.Documents.Open (directory & fileName)
On Error Resume Next
intpage = CInt(InputBox("Which page to print?"))
intcopies = CInt(InputBox("How many copies?"))
On Error GoTo 0
If intpage * intcopies <> 0 Then
For i = 1 To intcopies ' Loop to print next page of uer Choice Note: simplex is not working in my Office, Default Duplex
'### HERE IS THE PROBLEM###
objWord.PrintOut Range:=wdPrintRangeOfPages, Pages:=intpage
Next
Else
MsgBox "sorry, wrong page or copies, try again"
End If
'Next
objWord.Documents.Close
'set file to next in Dir
fileName = Dir()
Loop
'wdPrintRangeOfPages'是Word對象庫中定義的常量--Excel並不知道它是什麼。要麼添加對Word庫的引用,要麼替換實際值。 –
我是學習者,我不知道如何編碼,你能提示確切的代碼 – Bharath
把'4'代替'wdPrintRangeOfPages' –