automatically download and print a pdf file from the Internet

T

Tobias Widmer

Hi to all

I have a problem with the following Macro, if I start the macro in the
editor step by step it works perfectly ( it downloads a file from the
Net and automatically prints it out), but if i assign the Macro to a
button in the excel file and i then start the macro by pressing the
button i get an error message ("The file does not exist! bla bla...")
Does anybody know a solution to this problem or knows another macro to
produce the same?
thank you in advanced....

The macro:

Private Declare
Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA"
(ByVal pCaller As Long, ByVal szURL$, ByVal szFileName$, ByVal
dwReserved As Long, ByVal lpfnCB As Long) As Long

Public 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

Sub printmakro()

Product = "C:\Example.pdf"
If Worksheets(1).CheckBox1.Value = True Then
sURL$ = "http://www.example.com/example.pdf"
sLocalFile$ = Product
lResult = URLDownloadToFile(0, sURL$, sLocalFile$, 0, 0)

'I tried with DoEvents but it did not work

ShellExecute 0, "Print", Product, "", "", SHOWMAXIMIZED

Kill (Product)

End If
End Sub


Regards Tobias Widmer
 
T

Tom Ogilvy

perhaps

Sub printmakro()

Product = "C:\Example.pdf"
If Worksheets(1).CheckBox1.Value = True Then
sURL$ = "http://www.example.com/example.pdf"
sLocalFile$ = Product
lResult = URLDownloadToFile(0, sURL$, sLocalFile$, 0, 0)

'I tried with DoEvents but it did not work

do while dir(Product) = ""
DoEvents
Loop

ShellExecute 0, "Print", Product, "", "", SHOWMAXIMIZED

Kill (Product)

End If
End Sub
 

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