View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
[email protected] mike.d.moore@gmail.com is offline
external usenet poster
 
Posts: 1
Default Printing to word from excel

I am new to coding and I have a question on how to print a word doc
from excel and place some text on the word doc from the excel file. I
have gotten as far as printing the word doc from excel. I used this
code I found in this group. I have a spot for typing the cusotmer name
and address in the excel file and I would like to have that information
placed in a bookmarked form field in the word doc so it prints out.
Also I would like for the user to see a box that allows them to choose
the printer instead of the print out just going to the default printer.

See below code:

Sub cmdPrintCoverLetter()

Dim bStarted As Boolean
Dim oApp As Word.Application

On Error Resume Next
Set oApp = GetObject(, "Word.Application")
'Get the running instance of Word, if there is no instance
'create a new one:
If Err < 0 Then
bStarted = True
Set oApp = CreateObject("Word.Application")
End If

oApp.Activate
oApp.Visible = True
'Open document
oApp.Documents.Open Filename:="c:\remodel\CoverLetter.doc"

'Print file
oApp.ActiveDocument.PrintOut
oApp.ActiveDocument.Close savechanges:=wddonotsavechanges
'Quit only when Word was not running when we started this code
If bStarted Then
oApp.Quit
End If

Set oApp = Nothing

End Sub