ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Printing to word from excel (https://www.excelbanter.com/excel-programming/374680-printing-word-excel.html)

[email protected]

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


Gary L Brown

Printing to word from excel
 
I would like to have that information
placed in a bookmarked form field in the word doc so it prints out.

- Why not used a Merged document created in Word and called from Excel?

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.

- Instead of this code...
oApp.ActiveDocument.PrintOut
Use this code...
oApp.Dialogs(wdDialogFilePrint).Show

HTH,
--
Gary Brown

If this post was helpful, please click the ''Yes'' button next to ''Was this
Post Helpfull to you?''.


" wrote:

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




All times are GMT +1. The time now is 02:14 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com