Link to home
Start Free TrialLog in
Avatar of dprager
dprager

asked on

How to print a webpage with VBA command

Hi all,

The following question shouldn't be so hard. I want to automaticly print the webpage that i requested with the code below and then close it again.Tthe file loaded in the webpage can be a jpg file, a tif file or a svg file. The last file can only be opened with mozilla or internet explorer.
The code works good so far but I don't know the command to use to print the webpage loaded in internet explorer and then clos it again.
Set s = CreateObject("InternetExplorer.application")
      s.Visible = True
      s.Navigate path & FileB
 
' command for printing the webpage
' command for closing the webpage

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of irudyk
irudyk
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Also, if you want the user to be able to pick the printer then use:
.ExecWB 6, 1, 2, 0
Avatar of dprager
dprager

ASKER

Thans for the code. It works great on a single command but when I use it in a loop I get the error " loop without Do. When I pull the code you gave out of the loop it works fine using other commands  or instructions. Can you tell me what I'm doing wrong?


Call ListFilesToTable("C:\Documents and Settings\801565\Desktop\Afrika\", "*.svg")
 
Dim file As String, path As String
Dim rst As DAO.Recordset
Set rst = CurrentDb.OpenRecordset("files")
Do Until rst.EOF
    rst.Edit
    path = rst!fpath
    file = rst!fname
        Set s = CreateObject("InternetExplorer.application")
        With s
            .Visible = True
            .Navigate path & file
                Do Until .ReadyState = 4
                    DoEvents
                Loop
            .ExecWB 6, 2, 2, 0
            .Quit
    rst.Update
    rst.MoveNext
Loop
 
rst.Close
 
End Sub

Open in new window

You are missing the
   End With
after the
   .Quit

See revised code
Call ListFilesToTable("C:\Documents and Settings\801565\Desktop\Afrika\", "*.svg")
 
Dim file As String, path As String
Dim rst As DAO.Recordset
Set rst = CurrentDb.OpenRecordset("files")
Do Until rst.EOF
    rst.Edit
    path = rst!fpath
    file = rst!fname
        Set s = CreateObject("InternetExplorer.application")
        With s
            .Visible = True
            .Navigate path & file
                Do Until .ReadyState = 4
                    DoEvents
                Loop
            .ExecWB 6, 2, 2, 0
            .Quit
        End With
    rst.Update
    rst.MoveNext
Loop
 
rst.Close
 
End Sub

Open in new window

Avatar of dprager

ASKER

I should have known that last question. Feeling kinda stupid now.

Thanks for the help guys !! it works great.