Consulting

Results 1 to 7 of 7

Thread: Solved: Execute Commands in IE From Access

  1. #1
    VBAX Contributor
    Joined
    Jun 2004
    Location
    Texas
    Posts
    139
    Location

    Solved: Execute Commands in IE From Access

    Hi, all,

    I'm using the following chunk of code to output an Access query into HTML, then open the HTML file in Internet Explorer. The next step I would LIKE to accomplish is to select and copy the table from the Explorer window. I keep thinking that this should be simple enough, since Select All and Copy are just Edit menu commands, but I have not yet determined how to execute these commands in the Explorer window from my Access VBA. Any thoughts? Thanks in advance!!

    [VBA]
    Private Sub Command110_Click()
    Dim strPath As String, strOCR As String
    Dim objIE As InternetExplorer
    strPath = FixPath(CurrentProject.Path)
    strOCR = strPath & "temp_ocr.html"

    DoCmd.OutputTo acQuery, "QyOCR_Table_HTML", "HTML(*.html)", strOCR, False, ""

    Set objIE = New InternetExplorer
    With objIE
    .Navigate strOCR
    .Visible = True
    End With

    End Sub

    [/VBA]
    With program specs this fickle, you've just got to believe in Discord.

  2. #2
    BoardCoder VBAX Regular
    Joined
    May 2004
    Location
    Istanbul, Turkiye
    Posts
    73
    Hi,

    IE Object's ExecWB method for Select All and Copy action.

    [VBA]Private Sub Command110_Click()
    Dim strPath As String, strOCR As String
    Dim objIE As InternetExplorer
    strPath = FixPath(CurrentProject.Path)
    strOCR = strPath & "\temp_ocr.html"

    DoCmd.OutputTo acQuery, "Query1", "HTML(*.html)", strOCR, False, ""

    Set objIE = New InternetExplorer
    With objIE
    .Navigate strOCR
    .Visible = True
    End With

    'Select All
    objIE.ExecWB 17,2 'OLECMDID_SELECTALL, OLECMDEXECOPT_DONTPROMPTUSER
    'Copy Selection
    objIE.ExecWB 12,2 'OLECMDID_COPY, OLECMDEXECOPT_DONTPROMPTUSER
    'Clear Selection
    objIE.ExecWB 18,2 'OLECMDID_CLEARSELECTION, OLECMDEXECOPT_DONTPROMPTUSER

    End Sub[/VBA]

    I hope helps.
    Suat

  3. #3
    VBAX Contributor
    Joined
    Jun 2004
    Location
    Texas
    Posts
    139
    Location
    Okay, I'm running this piece of code:

    [VBA]
    Set objIE = New InternetExplorer
    With objIE
    .Navigate strOCR
    .Visible = True
    End With

    objIE.ExecWB 17, 2 'OLECMDID_SELECTALL, OLECMDEXECOPT_DONTPROMPTUSER

    objIE.ExecWB 12, 2 'OLECMDID_COPY, OLECMDEXECOPT_DONTPROMPTUSER

    [/VBA]
    And I'm getting this error message:

    -2147221248: Method ?ExecWB? of object ?IwebBrowser2? failed

    Any ideas on what is causing that?
    With program specs this fickle, you've just got to believe in Discord.

  4. #4
    BoardCoder VBAX Regular
    Joined
    May 2004
    Location
    Istanbul, Turkiye
    Posts
    73
    Please check your project references (VBA->Tools->References) and see if you have Microsoft Internet Controls is added in your project.

    If it doesn't exist then please let us know which references you have.

    Attaching your db here might help a lot (if not confidential).

    Suat

  5. #5
    Site Admin
    The Princess
    VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    Is this solved, eed?
    Or can we help you further?
    ~Anne Troy

  6. #6
    VBAX Contributor
    Joined
    Jun 2004
    Location
    Texas
    Posts
    139
    Location
    I'm sorry, yes, it's solved, well, closed, at least. My references were set, but I never could determine what was causing the error message.

    My solution was giving up on the IE idea and just manipulating the HTML file through Word. I knew from the start of this post that was an option; it would have been a bonus to make the IE process work, but it wasn't necessary to my procedure, so I'm skipping it.

    Thanks anyway for everyone's great suggestions!
    With program specs this fickle, you've just got to believe in Discord.

  7. #7
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    Great.

    I think people who ask the questions can now mark their questions solved using the Thread Tools dropdown at the top of the thread, so... feel free from now on.

    Thanks for getting back so quick!
    ~Anne Troy

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •