Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / December 2006

Tip: Looking for answers? Try searching our database.

printing an external document

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Steve - 19 Dec 2006 00:12 GMT
I am using a VBA control - Command button. and I would like to be able to
print a word document by pressing it. The file is a fax cover sheet, which is
an important part of the application I am making.

Is there anyway this can be achieved.

Thank you to all who are able to help
Nick Hodge - 19 Dec 2006 00:31 GMT
Steve

This automates Word from Excel and uses early binding, so you would need to
set a reference to the MS Word library under references... in the VBE
(Alt+F11) before running the code

Sub AutomateWord()
Dim wdApp As Word.Application
Dim wdDoc As Word.Document
Set wdApp = New Word.Application
Set wdDoc = wdApp.Documents.Open("C:\FaxCover.doc")
wdDoc.PrintOut
wdDoc.Close SaveChanges:=False
Set wdDoc = Nothing
wdApp.Quit
Set wdApp = Nothing
End Sub

Signature

HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
nick_hodgeTAKETHISOUT@zen.co.ukANDTHIS
www.nickhodge.co.uk

>I am using a VBA control - Command button. and I would like to be able to
> print a word document by pressing it. The file is a fax cover sheet, which
[quoted text clipped - 4 lines]
>
> Thank you to all who are able to help
NickHK - 20 Dec 2006 05:22 GMT
Steve,
Maybe the ShellExecute API with the Operation set to "print". Then you do
not need to know which application to open; the default for that file type
is used.

Private Declare Function ShellExecute Lib "shell32.dll" Alias
"ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal
lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String,
ByVal nShowCmd As Long) As Long

Dim RetVal As Long

RetVal = ShellExecute(&O0, "print", "C:\Doc.doc", vbNullString,
vbNullString, &O0)
If RetVal <= 32 Then
   MsgBox "Error: Cannot print"
End If

NickHK

> I am using a VBA control - Command button. and I would like to be able to
> print a word document by pressing it. The file is a fax cover sheet, which is
[quoted text clipped - 3 lines]
>
> Thank you to all who are able to help
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.