Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to print a webpage with VBA command

Posted on 2008-06-25
5
Medium Priority
?
1,568 Views
Last Modified: 2013-11-27
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

0
Comment
Question by:dprager
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 23

Accepted Solution

by:
irudyk earned 200 total points
ID: 21868479
Try the following code
Set s = CreateObject("InternetExplorer.application")
      
With s
    .Visible = True
    .Navigate "http://www.taylorleibow.com/home.asp"
    
    ' command for printing the webpage
    Do Until .ReadyState = 4 'READYSTATE_COMPLETE
      DoEvents
    Loop
 
    .ExecWB 6, 2, 2, 0 'OLECMDID_PRINT,OLECMDEXECOPT_DONTPROMPTUSER,PRINT_WAITFORCOMPLETION,0
 
' command for closing the webpage
    .Quit
End With

Open in new window

0
 
LVL 23

Expert Comment

by:irudyk
ID: 21868528
Also, if you want the user to be able to pick the printer then use:
.ExecWB 6, 1, 2, 0
0
 
LVL 1

Author Comment

by:dprager
ID: 21873135
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

0
 
LVL 23

Expert Comment

by:irudyk
ID: 21874037
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

0
 
LVL 1

Author Comment

by:dprager
ID: 21881281
I should have known that last question. Feeling kinda stupid now.

Thanks for the help guys !! it works great.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question