Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Jun 2009
    Location
    Hemet CA
    Posts
    310
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Talking

    I have an Excel Userform that I want to be able to print a word document from
    here is what I have so far.

    Code:
    Set wordapp = CreateObject("Word.Application")
    Set worddoc = wordapp.Documents.Open(ThisWorkbook.Path & "\Additional Inspection Files\Invoice.docm")
    	wordapp.Visible = True
    	wordapp.PrintOut
    	wordapp.Close

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    If you only want to print the document, you don't need to make Word visible.
    Close is not a method of the Word Application object, but of individual documents. So you could use

    Set wordapp = CreateObject("Word.Application")
    Set worddoc = wordapp.Documents.Open(ThisWorkbook.Path & "\Additional Inspection Files\Invoice.docm")
    worddoc.PrintOut
    worddoc.Close SaveChanges:=False
    Set worddoc = Nothing
    wordapp.Quit
    Set wordapp = Nothing

    A different option is to simulate selecting Print from the right-click menu of the document in Windows Explorer. To do this, copy the following code to the top of the module (before all subs and functions):

    Code:
    Public Declare Function ShellExecute _
      Lib "shell32.dll" Alias "ShellExecuteA" ( _
      ByVal hwnd As Long, _
      ByVal lpOperation As String, _
      ByVal lpFile As String, _
      ByVal lpParameters As String, _
      ByVal lpDirectory As String, _
      ByVal nShowCmd As Long) As Long
    
    Public Const SW_SHOWNORMAL = 1
    To print the document:

    Code:
    ShellExecute 0&, "Print", ThisWorkbook.Path & _
      "\Additional Inspection Files\Invoice.docm", 0&, 0&, SW_SHOWNORMAL

  3. #3
    3 Star Lounger
    Join Date
    Jun 2009
    Location
    Hemet CA
    Posts
    310
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi HansV
    Thank you so very much for all your assistance, its works perfect....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •