Printing in Word

jbailey2

Board Regular
Joined
Jan 5, 2003
Messages
97
The following command is causing an error the first time the macro is run (the second time it works fine!)

AppWord.Dialogs(wdDialogFilePrint).Show

is causing the following error

Run-time error '5941':
The Requested Member of the Collection does not exist.


Any suggestions? I am establishing a reference to the Microsoft Word Object Library so that is not the problem and the command works fine the second time the macro is run! I am using the following code prior to the above line:

'create a new word instance
Dim AppWord As Object
Set AppWord = CreateObject("Word.Application")

'open file
AppWord.Documents.Open FileName:=TemplatesDir & InfoPack, PasswordDocument:=AdminPass

'set bookmarks
With AppWord
If CustomerName <> "" Then
.ActiveDocument.Bookmarks("CustName").Select
.Selection.typetext Text:=(CustomerName)
.ActiveDocument.Bookmarks("CustName2").Select
.Selection.typetext Text:=(CustomerName)
End If
End With

'display print dialog box
Application.ScreenUpdating = True
AppWord.Visible = True
AppWord.Dialogs(wdDialogFilePrint).Show[/i]
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Hello JB,

Any suggestions? I am establishing a reference to the Microsoft Word Object Library so that is not the problem and the command works fine the second time the macro is run! I am using the following code prior to the above line:

If you set the appropriate reference for the appropriate project (the one the code's being run from, in Excel), AppWord.Dialogs(wdDialogFilePrint).Show should work just fine every time.

That aside, the following is much like a fox in the hen house, it has chicken for supper every time any way you slice it.

AppWord.Dialogs(88).Show

Hope this helps.
 
Upvote 0

Forum statistics

Threads
1,221,701
Messages
6,161,381
Members
451,700
Latest member
Eccymarge

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top