Print button in Word

  • Thread starter doug via OfficeKB.com
  • Start date
D

doug via OfficeKB.com

What code do I use for a button that I want to print the page it is on as
well as other word files on the hard drive?
Thanks
 
D

doug via OfficeKB.com

I used this code, but it doesn't do anything:

Private Sub Command96_Click()
Dim wordobj As Object
Set wordobj = CreateObject("Word.Basic")
wordobj.FileOpen "N:\Customer Service\Direct Team\Procedure Guide\
2005 Profiles\abf 2005.doc"
wordobj.AppShow
wordobj.fileprint
wordobj.filesave
wordobj.FileClose (1)
wordobj.appclose
Set wordobj = Nothing
Set wordobj = CreateObject("Word.Basic")
wordobj.FileOpen "N:\Customer Service\Direct Team\Procedure Guide\
DAILY TASKS\ABF\ABF DAILY TASKS.doc"
wordobj.AppShow
wordobj.fileprint
wordobj.filesave
wordobj.FileClose (1)
wordobj.appclose
Set wordobj = Nothing
Set wordobj = CreateObject("Word.Basic")
wordobj.FileOpen "N:\Customer Service\Direct Team\Procedure Guide\
DAILY TASKS\ABF\ABF CONTACTS.doc"
wordobj.AppShow
wordobj.fileprint
wordobj.filesave
wordobj.FileClose (1)
wordobj.appclose
Set wordobj = Nothing
End Sub
 
H

Helmut Weber

Hi,

how did you arrive at wordbasic?
What code do I use for a button that I want to print
the page it is on as well as other word files on the hard drive?

"The page it is on" doesn't go together with "other word files",
as no other word file is a page.

And not even the most advanced ultimate experts here
will be able to write a macro to print "other word files".

As often, the question is the problem, not the answer.

Greetings from Bavaria, Germany

Helmut Weber, MVP, WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
D

doug via OfficeKB.com

I was looking for the code that would allow me to use a button, to print the
page the button is on as well as two word files that are on the hard drive.
I don't know how else to say it.
 
H

Helmut Weber

Hi,
to print the page the button is on

You mean to print the actual page!
Your button is to be seen on all pages, I guess.
If you could hide the button for some specially defined pages,
then you would be among the grand masters here.

Forgive me for saying so, I'm really trying to be friendly,
but the right question is the key to the solution.

Select the page.
That's all, I think, for which you need help.
Select the page, like:
Selection.Bookmarks("\page").Select

Print the selection. Like, untested,
as I don't even have a printer, (I do printing in the office) ;-),
ActiveDocument.PrintOut Range:=wdPrintSelection

plus the code recorded by printing some other docs.

HTH

Greetings from Bavaria, Germany

Helmut Weber, MVP, WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
D

doug via OfficeKB.com

Ok let me try and explain it better.
I have a company profile in Word. I want to put a button on the profile that
would print that profile. I also have accompnaying word files that are
seperate. I do not want to put buttons on these other pages.
When I click the button on the profile I want it to print the profile and the
other seperate documents.

The code I posted earlier is from an Access button I made. I press a button
in access and it prints the profile and other seperate documents. However I
want to put the button in Word in the profile instead of in access. The code
from access is not working when I use it for a button in Word. I have no
idea why it won't work.
 
H

Helmut Weber

Hi,

if you show us the code,
we might be able to adapt it to word.

Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000
 
H

Helmut Weber

Hi Doug,

like this:

Sub MyPrint()
Dim l As Long
Dim oDoc As Document
Dim sNames(2) As String ' zero based array

sNames(0) = "c:\test\word\test1.doc"
sNames(1) = "c:\test\word\test1.doc"
sNames(2) = "c:\test\word\test1.doc"

For l = 0 To 2
Set oDoc = Documents.Open(sNames(l))
oDoc.PrintOut Background:=False
' no testing possibility for printing right now
' Background:=False is highly recommended
oDoc.Save ' might not be necessary
oDoc.Close
Next
End Sub

HTH

Greetings from Bavaria, Germany

Helmut Weber, MVP, WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top