[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.excel.programming

printing an external document

Steve

12/19/2006 12:12:00 AM

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
2 Answers

Nick Hodge

12/19/2006 12:32:00 AM

0

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

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


"Steve" <Steve@discussions.microsoft.com> wrote in message
news:D9F91654-3D2D-4672-86C5-305FA97BF61D@microsoft.com...
>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

NickHK

12/20/2006 5:23:00 AM

0

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

"Steve" <Steve@discussions.microsoft.com> wrote in message
news:D9F91654-3D2D-4672-86C5-305FA97BF61D@microsoft.com...
> 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