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

I wish to create a spreadsheet which will have a series of
buttons on it linking to a collection of Word documents.
What would the code be to print a Word document from an
Excel macro. Ideally i would like the Print dialogue
window to appear so that i can specify the number of
copies before printing.

Any help would be greatly appreciated.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 176
Default Printing a Word doc from Excel

Danny,

I don't know how to put up the word dialog to set the number of
copies, but the code below will do the same thing: set your file path
and name where obvious. The code requires that you set a reference to
Word in your project - set your reference to the oldest version of
Word that your users will be using, since references only
automatically update from older to newer versions but not newer to
older.

HTH,
Bernie

Sub PrintWordDocument()
Dim oWord As Word.Application

Set oWord = CreateObject("word.application")

oWord.Documents.Open "C:\folder\Word file name.doc"
oWord.PrintOut Copies:=Application.InputBox _
("Number of Copies?", , , , , , , 1)

oWord.Application.Quit (False)
End Sub



"Danny" wrote in message
...
I wish to create a spreadsheet which will have a series of
buttons on it linking to a collection of Word documents.
What would the code be to print a Word document from an
Excel macro. Ideally i would like the Print dialogue
window to appear so that i can specify the number of
copies before printing.

Any help would be greatly appreciated.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Printing a Word doc from Excel

Tried the method below and could not get it to work. I
have very limited VBA knowledge and i could not work out
where i tell it that i want it to work on Word 97 and
above? Any help would be appreciated.

Danny.


-----Original Message-----
Danny,

I don't know how to put up the word dialog to set the

number of
copies, but the code below will do the same thing: set

your file path
and name where obvious. The code requires that you set a

reference to
Word in your project - set your reference to the oldest

version of
Word that your users will be using, since references only
automatically update from older to newer versions but not

newer to
older.

HTH,
Bernie

Sub PrintWordDocument()
Dim oWord As Word.Application

Set oWord = CreateObject("word.application")

oWord.Documents.Open "C:\folder\Word file name.doc"
oWord.PrintOut Copies:=Application.InputBox _
("Number of Copies?", , , , , , , 1)

oWord.Application.Quit (False)
End Sub



"Danny" wrote in

message
...
I wish to create a spreadsheet which will have a series

of
buttons on it linking to a collection of Word documents.
What would the code be to print a Word document from an
Excel macro. Ideally i would like the Print dialogue
window to appear so that i can specify the number of
copies before printing.

Any help would be greatly appreciated.



.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Printing a Word doc from Excel

Hi Danny

1) Go to the VBA editor, Alt -F11
2) ToolsReferences in the Menu bar
3) Place a Checkmark before Microsoft Word? Object Library
? is the Excel version number

--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2002 SP-2)
www.rondebruin.nl



"Danny" wrote in message ...
Tried the method below and could not get it to work. I
have very limited VBA knowledge and i could not work out
where i tell it that i want it to work on Word 97 and
above? Any help would be appreciated.

Danny.


-----Original Message-----
Danny,

I don't know how to put up the word dialog to set the

number of
copies, but the code below will do the same thing: set

your file path
and name where obvious. The code requires that you set a

reference to
Word in your project - set your reference to the oldest

version of
Word that your users will be using, since references only
automatically update from older to newer versions but not

newer to
older.

HTH,
Bernie

Sub PrintWordDocument()
Dim oWord As Word.Application

Set oWord = CreateObject("word.application")

oWord.Documents.Open "C:\folder\Word file name.doc"
oWord.PrintOut Copies:=Application.InputBox _
("Number of Copies?", , , , , , , 1)

oWord.Application.Quit (False)
End Sub



"Danny" wrote in

message
...
I wish to create a spreadsheet which will have a series

of
buttons on it linking to a collection of Word documents.
What would the code be to print a Word document from an
Excel macro. Ideally i would like the Print dialogue
window to appear so that i can specify the number of
copies before printing.

Any help would be greatly appreciated.



.



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Printing a Word doc from Excel

The code runs now and the printer comes up in the taskbar
as if it is printing, but then nothing gets through to the
printer?

Here is my code -


Sub Rectangle2_Click()
Dim oWord As Word.Application

Set oWord = CreateObject("word.application")

oWord.Documents.Open "C:\Test.doc"
oWord.PrintOut Copies:=Application.InputBox _
("Number of Copies?", , , , , , , 1)

oWord.Application.Quit (False)

End Sub

I can follow most of the code but don't understand how the
input box is telling the printer how many copies it wants.
This code seems too simple for this complex task? Could
someone explain how this is working and why my document
never actually gets printed?

Thanks Danny.


-----Original Message-----
Hi Danny

1) Go to the VBA editor, Alt -F11
2) ToolsReferences in the Menu bar
3) Place a Checkmark before Microsoft Word? Object Library
? is the Excel version number

--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2002 SP-2)
www.rondebruin.nl



"Danny" wrote in

message ...
Tried the method below and could not get it to work. I
have very limited VBA knowledge and i could not work out
where i tell it that i want it to work on Word 97 and
above? Any help would be appreciated.

Danny.


-----Original Message-----
Danny,

I don't know how to put up the word dialog to set the

number of
copies, but the code below will do the same thing: set

your file path
and name where obvious. The code requires that you

set a
reference to
Word in your project - set your reference to the oldest

version of
Word that your users will be using, since references

only
automatically update from older to newer versions but

not
newer to
older.

HTH,
Bernie

Sub PrintWordDocument()
Dim oWord As Word.Application

Set oWord = CreateObject("word.application")

oWord.Documents.Open "C:\folder\Word file name.doc"
oWord.PrintOut Copies:=Application.InputBox _
("Number of Copies?", , , , , , , 1)

oWord.Application.Quit (False)
End Sub



"Danny" wrote in

message
...
I wish to create a spreadsheet which will have a

series
of
buttons on it linking to a collection of Word

documents.
What would the code be to print a Word document from

an
Excel macro. Ideally i would like the Print dialogue
window to appear so that i can specify the number of
copies before printing.

Any help would be greatly appreciated.


.



.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Printing a Word doc from Excel

Hi

Is working for me

Try this

Sub test()
Dim WD As Object
Set WD = CreateObject("Word.Application")
WD.Documents.Open ("C:\ron.doc")
WD.ActiveDocument.PrintOut Copies:=Application.InputBox _
("Number of Copies?", , , , , , , 1)
WD.Quit
Set WD = Nothing
End Sub

Copies is a part of the PrintOut code
See the VBA help for PrintOut

--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2002 SP-2)
www.rondebruin.nl



"Danny" wrote in message ...
The code runs now and the printer comes up in the taskbar
as if it is printing, but then nothing gets through to the
printer?

Here is my code -


Sub Rectangle2_Click()
Dim oWord As Word.Application

Set oWord = CreateObject("word.application")

oWord.Documents.Open "C:\Test.doc"
oWord.PrintOut Copies:=Application.InputBox _
("Number of Copies?", , , , , , , 1)

oWord.Application.Quit (False)

End Sub

I can follow most of the code but don't understand how the
input box is telling the printer how many copies it wants.
This code seems too simple for this complex task? Could
someone explain how this is working and why my document
never actually gets printed?

Thanks Danny.


-----Original Message-----
Hi Danny

1) Go to the VBA editor, Alt -F11
2) ToolsReferences in the Menu bar
3) Place a Checkmark before Microsoft Word? Object Library
? is the Excel version number

--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2002 SP-2)
www.rondebruin.nl



"Danny" wrote in

message ...
Tried the method below and could not get it to work. I
have very limited VBA knowledge and i could not work out
where i tell it that i want it to work on Word 97 and
above? Any help would be appreciated.

Danny.


-----Original Message-----
Danny,

I don't know how to put up the word dialog to set the
number of
copies, but the code below will do the same thing: set
your file path
and name where obvious. The code requires that you

set a
reference to
Word in your project - set your reference to the oldest
version of
Word that your users will be using, since references

only
automatically update from older to newer versions but

not
newer to
older.

HTH,
Bernie

Sub PrintWordDocument()
Dim oWord As Word.Application

Set oWord = CreateObject("word.application")

oWord.Documents.Open "C:\folder\Word file name.doc"
oWord.PrintOut Copies:=Application.InputBox _
("Number of Copies?", , , , , , , 1)

oWord.Application.Quit (False)
End Sub



"Danny" wrote in
message
...
I wish to create a spreadsheet which will have a

series
of
buttons on it linking to a collection of Word

documents.
What would the code be to print a Word document from

an
Excel macro. Ideally i would like the Print dialogue
window to appear so that i can specify the number of
copies before printing.

Any help would be greatly appreciated.


.



.



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Printing a Word doc from Excel

Try this

Set WD = CreateObject("Word.Application")
WD.Documents.Open ("C:\ron.doc")
WD.ActiveDocument.PrintOut
WD.Quit
Set WD = Nothing


--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2002 SP-2)
www.rondebruin.nl



"Danny" wrote in message ...
I wish to create a spreadsheet which will have a series of
buttons on it linking to a collection of Word documents.
What would the code be to print a Word document from an
Excel macro. Ideally i would like the Print dialogue
window to appear so that i can specify the number of
copies before printing.

Any help would be greatly appreciated.



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Printing a Word doc from Excel

Dim WD As Object

I forgot this line

--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2002 SP-2)
www.rondebruin.nl



"Danny" wrote in message ...
I wish to create a spreadsheet which will have a series of
buttons on it linking to a collection of Word documents.
What would the code be to print a Word document from an
Excel macro. Ideally i would like the Print dialogue
window to appear so that i can specify the number of
copies before printing.

Any help would be greatly appreciated.



  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Printing a Word doc from Excel

Thanks for this. The code worked and printed out the
document. Is there not a way i can get the print dialogue
box up before printing this way the user can enter how
many copies they want? Alternatively a simple window
asking for a user input for the number of copies would be
even better.

How do i put a delay on closing Word cause i currently get
the quitting word will cancel all print jobs message?

Thanks a lot,


Danny.


-----Original Message-----
Dim WD As Object

I forgot this line

--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2002 SP-2)
www.rondebruin.nl



"Danny" wrote in

message ...
I wish to create a spreadsheet which will have a series

of
buttons on it linking to a collection of Word documents.
What would the code be to print a Word document from an
Excel macro. Ideally i would like the Print dialogue
window to appear so that i can specify the number of
copies before printing.

Any help would be greatly appreciated.



.

  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Printing a Word doc from Excel

Use the example from Bernie for the copies

How do i put a delay on closing Word cause i currently get
the quitting word will cancel all print jobs message?


Check out DisplayAlerts in the VBA help for th

--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2002 SP-2)
www.rondebruin.nl



"Danny" wrote in message ...
Thanks for this. The code worked and printed out the
document. Is there not a way i can get the print dialogue
box up before printing this way the user can enter how
many copies they want? Alternatively a simple window
asking for a user input for the number of copies would be
even better.

How do i put a delay on closing Word cause i currently get
the quitting word will cancel all print jobs message?

Thanks a lot,


Danny.


-----Original Message-----
Dim WD As Object

I forgot this line

--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2002 SP-2)
www.rondebruin.nl



"Danny" wrote in

message ...
I wish to create a spreadsheet which will have a series

of
buttons on it linking to a collection of Word documents.
What would the code be to print a Word document from an
Excel macro. Ideally i would like the Print dialogue
window to appear so that i can specify the number of
copies before printing.

Any help would be greatly appreciated.



.





  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 117
Default Printing a Word doc from Excel

Danny,

I took a Word document with some boilerplate text and inserted a bookmark
that I named "Bookmark1" I saved it as a Word template rather than a Word
document. The macro below will open Word if it isn't already open, load the
template, insert whatever I have in cell A1 on sheet 1 immediately after the
bookmark, bring up the print dialog, execute the print after I set the
number of copies and it will close word without warnings or saving the new
document. See if you can modify it to fit your needs.

Sub PrintFromTemplate()
Dim bStarted As Boolean
Dim oApp As Word.Application
Dim str1 As String

str1 = Sheets("Sheet1").Cells(1, 1).Value

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
oApp.Documents.Add Template:="Test.dot"

oApp.ActiveDocument.Bookmarks("Bookmark1").Range.I nsertAfter str1

oApp.Dialogs(wdDialogFilePrint).Show
oApp.ActiveDocument.PrintOut Background:=False, Copies:=0

oApp.ActiveDocument.Close 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


Steve


"Danny" wrote in message
...
Thanks for this. The code worked and printed out the
document. Is there not a way i can get the print dialogue
box up before printing this way the user can enter how
many copies they want? Alternatively a simple window
asking for a user input for the number of copies would be
even better.

How do i put a delay on closing Word cause i currently get
the quitting word will cancel all print jobs message?

Thanks a lot,


Danny.


-----Original Message-----
Dim WD As Object

I forgot this line

--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2002 SP-2)
www.rondebruin.nl



"Danny" wrote in

message ...
I wish to create a spreadsheet which will have a series

of
buttons on it linking to a collection of Word documents.
What would the code be to print a Word document from an
Excel macro. Ideally i would like the Print dialogue
window to appear so that i can specify the number of
copies before printing.

Any help would be greatly appreciated.



.



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
Printing Word Documents from Excel Richard Excel Discussion (Misc queries) 0 June 13th 08 04:20 PM
Printing from email without Word/Excel mejsunflower Excel Worksheet Functions 1 May 6th 05 03:12 PM
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
Printing Word doc from Excel Ed Stevens[_2_] Excel Programming 1 October 17th 03 02:15 PM


All times are GMT +1. The time now is 02:53 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"