Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Printing a Word doc from Excel VBA code

Thanks to John Walkenbach's Excel 2003 Power Programming, I can populate a
Word template with Excel data and save the doc file, but I can't figure out
the code to print the document so that I don't have to reopen it.

Can anyone help?
Thanks,
Bruce
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Printing a Word doc from Excel VBA code

I found the answer in a 7/19/05 reply by Henry. I guess my problem was not
the wrdApp.PrintOut code, but that I needed to give Word time to print it
before closing it:
wrdApp.PrintOut
Application.Wait Time + TimeValue("00:00:05")

If anyone has any further comments or clarifications I would appreciate it.
Thanks,
Bruce

"BruceInMiami" wrote:

Thanks to John Walkenbach's Excel 2003 Power Programming, I can populate a
Word template with Excel data and save the doc file, but I can't figure out
the code to print the document so that I don't have to reopen it.

Can anyone help?
Thanks,
Bruce

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Printing a Word doc from Excel VBA code

There's an option in MSWord that you can turn off.

Tools|Options|print tab|uncheck background printing

Then word will wait until the print job finishes.

A longggg time ago, (word95???), background printing caused trouble printing
tables or shapes or something. As a habit, I always turn this option off.
(Although, newer versions of MSWord may have been fixed.)

In code, you could do something like:

Option Explicit
Sub Testme()

Dim WDApp As Object
Dim WDDoc As Object
Dim myDocName As String
Dim myPrintBackground As Boolean

myDocName = "c:\my documents\word\doc2.doc"

Set WDApp = CreateObject("Word.Application")
WDApp.Visible = True 'at least for testing!

Set WDDoc = WDApp.documents.Open(Filename:=myDocName)

myPrintBackground = WDApp.Options.printbackground
WDApp.Options.printbackground = False
WDDoc.PrintOut
WDApp.Options.printbackground = myPrintBackground
WDDoc.Close savechanges:=False

WDApp.Quit

Set WDDoc = Nothing
Set WDApp = Nothing

End Sub

If you step through the code, you should see a slight delay while the wdapp.quit
is finishing up.


BruceInMiami wrote:

I found the answer in a 7/19/05 reply by Henry. I guess my problem was not
the wrdApp.PrintOut code, but that I needed to give Word time to print it
before closing it:
wrdApp.PrintOut
Application.Wait Time + TimeValue("00:00:05")

If anyone has any further comments or clarifications I would appreciate it.
Thanks,
Bruce

"BruceInMiami" wrote:

Thanks to John Walkenbach's Excel 2003 Power Programming, I can populate a
Word template with Excel data and save the doc file, but I can't figure out
the code to print the document so that I don't have to reopen it.

Can anyone help?
Thanks,
Bruce


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Embedding Word Docs into Excel Worksheets and Then Printing The Word Docs mr_melvis Excel Worksheet Functions 1 April 8th 05 03:00 AM
Printing MS Word Doc From MS Excel Anthony Excel Discussion (Misc queries) 2 March 16th 05 08:37 AM
Excel VBA printing to MS Word cause MS Word to crash, why? alruff Excel Programming 0 October 4th 04 09:57 PM
Printing Word Document using Excel Programming hangs Word Alan Excel Programming 0 September 30th 04 08:41 PM
Excel code to Wait until Word finishes printing before closing Mike Molyneaux[_2_] Excel Programming 2 October 24th 03 02:45 AM


All times are GMT +1. The time now is 12:09 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"