Results 1 to 11 of 11
  1. #1
    luckasx is offline Novice
    Windows 8 Access 2003
    Join Date
    Nov 2013
    Posts
    13

    VBA Internet Explorer Print Specific Page

    Hello, I'm opening a web page and need to print just the first two pages.

    Is it possible?

    I'm using this code..

    IEwindow.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    What is IEwindow? You need to get a hold of the Document from the Internet Explorer Application object. Maybe...

    Dim htmlDoc as HTMLDocument

    Set htmlDoc = ?AppObject?.Document

    htmlDoc.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER, Null, Null

    I have not had much luck bypassing the user prompt. You may be able to bypass when printing vs. saving. I have seen some creative examples to get a hold of the pop up and click the OK control in it.......

  3. #3
    luckasx is offline Novice
    Windows 8 Access 2003
    Join Date
    Nov 2013
    Posts
    13
    Quote Originally Posted by ItsMe View Post
    What is IEwindow? You need to get a hold of the Document from the Internet Explorer Application object. Maybe...

    Dim htmlDoc as HTMLDocument

    Set htmlDoc = ?AppObject?.Document

    htmlDoc.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER, Null, Null

    I have not had much luck bypassing the user prompt. You may be able to bypass when printing vs. saving. I have seen some creative examples to get a hold of the pop up and click the OK control in it.......
    I'm using a function to verify the title of the windows of IE and then Print if this is the window that I want to print

    Dim allExplorerWindows As New SHDocVw.ShellWindows
    Set allExplorerWindows = New SHDocVw.ShellWindows
    Dim IEwindow As SHDocVw.InternetExplorer
    Dim IEwindow As SHDocVw.InternetExplorer

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    You can try to print the Window. I have not tried it before. You just need to assign Null to the pvaIn and pvaOut.

    IEwindow.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER, Null, Null

    If that does not work then reference Microsoft Internet Controls and assign an internet explorer object to = Window object

    create an Internet explorer object

    Dim appInternet As InternetExplorer
    Set appInternet = IEwindow.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER, Null, Null

    Before, I was thinking you needed the Document Object but that is not the case. ExecWB is not within the scop od Document. But you could perhaps use another method to print from Document. It may format better.

  5. #5
    luckasx is offline Novice
    Windows 8 Access 2003
    Join Date
    Nov 2013
    Posts
    13
    But I need to print just the two first pages

  6. #6
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    I don't know what to say to that. Are you having succes printing? What object are you printing? As I mentioned, creating objects that are better focused on your target may format better.

  7. #7
    luckasx is offline Novice
    Windows 8 Access 2003
    Join Date
    Nov 2013
    Posts
    13
    I'm printing a web page, and printing with success all pages. But again, I need just the first two.

  8. #8
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    I believe there are ways to interact with printer DLL files to manipulate the printer settings. You would have to do some research on that. My memory is not producing a vivid picture right now. I would approach it by drilling down on the HTML elements I want and extracting those elements from the web page to a String. You may have to write to a text file, save it, and then send the text file to a printer.

  9. #9
    luckasx is offline Novice
    Windows 8 Access 2003
    Join Date
    Nov 2013
    Posts
    13
    I got it. But I solve changing margins numbers. =D

  10. #10
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    Perhaps you can share your solution here in this thread so others can benefit.

  11. #11
    luckasx is offline Novice
    Windows 8 Access 2003
    Join Date
    Nov 2013
    Posts
    13
    Just change margin number on Page Settings from Internet Explorer Menu

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Find Internet Explorer window based on specific site
    By redbull in forum Code Repository
    Replies: 0
    Last Post: 04-02-2013, 09:19 AM
  2. Replies: 2
    Last Post: 11-21-2012, 09:57 AM
  3. VBA > Internet Explorer
    By Stokecpa in forum Programming
    Replies: 3
    Last Post: 08-06-2012, 01:10 AM
  4. Internet Explorer automation with VBA
    By sa230e in forum Programming
    Replies: 0
    Last Post: 09-29-2011, 05:04 PM
  5. Replies: 3
    Last Post: 08-07-2011, 09:22 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums