none
Show Printer, Printer Properties dialog prior to Document.PrintOut RRS feed

  • Question

  • I am attempting to automate Word from Access VBA to print questionnaires for a set of study participants.  Each participant may have one or more questionnaires depending on their occupation(s) during the study period.  I have each questionnaire stored as a .dotx file so I can add the participant ID at the bottom of each page before printing.  For each participant I am currently able to loop through each relevant questionnaire, add the participant's ID to the footer, and print it to the default printer with whatever the current printing preferences are using the following code:

         '-----------------------------------------------------------------------------------
        ' Print each relevant hardcopy questionnaire, appending the survey id to each.
        '-----------------------------------------------------------------------------------
        For i = 0 To UBound(varOccupations)
            On Error GoTo Error_Handler_Exit

            strDoc = strPath & varOccupations(i) & ".dotx"

            objWord.Documents.Add strDoc
            objWord.Visible = True
            '-----------------------------------------------------------------------------------
            ' Add the participant ID to the footer of the questionnaire
            '-----------------------------------------------------------------------------------
            Set objRange = objWord.ActiveDocument.Bookmarks("SurveyID").Range
            objRange.Text = CStr(varSurveyID)
            objWord.ActiveDocument.Bookmarks.Add "SurveyID", objRange
            objWord.ActiveDocument.Bookmarks("SurveyID").Range.Font.Underline = wdUnderlineSingle

            objWord.ActiveDocument.PrintOut
            objWord.ActiveDocument.Close wdDoNotSaveChanges
        Next i

    I would like to be able to allow the user to select a printer and set printer preferences before the questionnaires print, and preferably before this loop (i.e., that user be prompted for print settings once per participant, not for every questionnaire).  I'd rather this not permanently change the default printer or the default printer preferences, but if it has to be done that way, that's ok.  I am hoping this can be done in the confines of the Word object model (as opposed to having to do API calls) which is why I'm asking this here.  I'm new at automation and any help in this regard is greatly appreciated.  Thanks!

    -Bruce

            
    Friday, June 16, 2017 8:19 PM

All replies

  • Hello Bruce,

    We could use code below to show print dialog.

    Sub ShowPrintDialog() 
     Dialogs(wdDialogFilePrint).Show 
    End Sub
    

    In your project, I think it would be

    objWord.Dialogs(wdDialogFilePrint).Show 

    For more information, you could visit Displaying Built-in Word Dialog Boxes & Built-in Dialog Box Argument Lists (Word)

    After checking the available built dialog list, I think there is no method to show Printer Properties dialog. The user could click the Properties in the Printer Dialog to open the Printer Properties dialog.

    Regards,

    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, June 19, 2017 2:05 AM
    Moderator
  • Thank you.

    I see that you have merged this post with another post I made in the Access developer's forum.  These are not the same issue.  One asks how to show a print dialog before printing an Access report.  The second asks how to show a print dialog when automating Word.  Please un-merge these. 

    -Bruce

    Monday, June 19, 2017 7:19 PM
  • Hello,

    I have unmerged them. Do you have any other problems with the issue related to Word object model? If your issue has been resolved, you could share your solution here and close this thread.

    Regards,

    Celeste 


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Tuesday, June 20, 2017 1:54 AM
    Moderator