dcsimg
Results 1 to 12 of 12

Thread: Convert VBA code calling IE to VBA code calling FireFox?

  1. #1

    Thread Starter
    Lively Member Emeroogork's Avatar
    Join Date
    Mar 2011
    Location
    Connecticut
    Posts
    102

    Convert VBA code calling IE to VBA code calling FireFox?

    Getting tired of IE not being able to work with VBA when it comes to URLs and web sites.

    My program invokes URLs on queue using OPEN_Url() and an hour later uses CLOSE_Url() subroutines. I have 4 URLs that work and 4 that do not. After the latest "Upgrade" of windows that is now 3 working and 5 failing.

    Here is my code followed by a few URLS that fail.

    -------------------------------------------------------------

    Sub Open_URL(ThisURL) 'June 21, 2015
    Dim obj As Object
    Set obj = CreateObject("InternetExplorer.Application")
    obj.Visible = True
    obj.Navigate ThisURL
    If Not StartUp Then
    TimeDelay = Now + TimeValue("00:59:55") '
    StartUp = False
    End If
    Range("I5:I5").Value = Hour(AlertTime)
    Application.OnTime TimeDelay, "Close_URL"

    End Sub
    '-----------------------------------------------------------
    Sub Close_URL() 'June 21, 2015
    Dim obj As Object: Dim ie As Object
    Set obj = CreateObject("shell.application")
    For Each ie In obj.Windows
    If TypeName(ie.Document) = "HTMLDocument" Then
    ie.Quit
    Exit For
    End If
    Next

    End Sub
    ' -------------------------------------------------------

    These fail in IE:

    These work in IE.

    They all work in Firefox.

    If the URL can be changes to get them to work with IE, I am open to suggestions.

  2. #2
    Addicted Member
    Join Date
    Sep 2006
    Posts
    218

    Re: Convert VBA code calling IE to VBA code calling FireFox?

    There was a nice thread on VBForums about this. To summarize (some of) the thread, you can do something like this to execute FF (or any executable for that matter)

    Code:
    Option Explicit
    
    Private 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
    
    
    Private Sub OpenURL( url as String )
        Dim filepath as String
        filepath = "D:\Program Files (x86)\Mozilla Firefox\firefox.exe"
        ShellExecute 0, "open", filepath, url, vbNullString, 1
    End Sub

    Alternatively, an ActiveX control for Firefox should let you create the Firefox object Firefox.Application. See here:

    http://www.iol.ie/~locka/mozilla/control.htm

  3. #3

    Thread Starter
    Lively Member Emeroogork's Avatar
    Join Date
    Mar 2011
    Location
    Connecticut
    Posts
    102

    Re: Convert VBA code calling IE to VBA code calling FireFox?

    Thanks for the quick response.
    I will check it out.

    The important part is that the instance of the browser is to be identifiable by software
    so that it can be closed automatically an hour later without any user intervention.

    As activeX, I wonder if I can place it and remove it by code. You got me thinking,,,,
    Last edited by Emeroogork; Jul 18th, 2015 at 03:51 PM. Reason: clarification

  4. #4
    Addicted Member
    Join Date
    Sep 2006
    Posts
    218

    Re: Convert VBA code calling IE to VBA code calling FireFox?

    I took a look at the source code and I'm pretty intrigued. If you give it a whirl can you report back your experience? I'd love to hear how this pans out.

  5. #5

    Thread Starter
    Lively Member Emeroogork's Avatar
    Join Date
    Mar 2011
    Location
    Connecticut
    Posts
    102

    Re: Convert VBA code calling IE to VBA code calling FireFox?

    Source code for mine?, the suggested changes to my Open_URL? or of the suggested other urls?

    I am not at the system to test any code but I wonder if the suggested Open_URL() will close the
    browser with the Close_URL() that I am using or do I need to modify that too.

    I am a bit blind at this as there are some lines that are foreign to me.

  6. #6
    PowerPoster
    Join Date
    Dec 2004
    Posts
    24,377

    Re: Convert VBA code calling IE to VBA code calling FireFox?

    The important part is that the instance of the browser is to be identifiable by software
    so that it can be closed automatically an hour later without any user intervention.
    you existing code (for ie) does not do this, it just closes all internet explorer windows, regardless of how they were opened

    there are APIs that can find all firefox windows and close them

    afaik the firefox activex is very old and should not be used, make sure to check when it was last updated
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  7. #7

    Thread Starter
    Lively Member Emeroogork's Avatar
    Join Date
    Mar 2011
    Location
    Connecticut
    Posts
    102

    Re: Convert VBA code calling IE to VBA code calling FireFox?

    Quote Originally Posted by westconn1 View Post
    you existing code (for ie) does not do this, it just closes all internet explorer windows, regardless of how they were opened

    there are APIs that can find all firefox windows and close them

    afaik the firefox activex is very old and should not be used, make sure to check when it was last updated
    I had the feeling that that is how it was working. I neither tested it with another IE instance open nor do I ever
    use IE anyhow so that it closes everything IE was not an issue.

    So, FF API will basically do the same thing but at least the URLs will work.

    Is there any device, activeX or not, that I can use to open a web site and then close the device, or change the
    web site, an hour later? I can control the timing but cannot seem to present/change/close the web site.

  8. #8
    Addicted Member
    Join Date
    Sep 2006
    Posts
    218

    Re: Convert VBA code calling IE to VBA code calling FireFox?

    A totally batty, off the wall idea...

    A few weeks ago I stumbled across references to Python for Excel. If it's true and you have access to the standard Python libraries, you can pretty much do *anything*.



    Westconn, just curious. COM is highly structured, high standardized, and AFAIK, hasn't had major refactoring since Win95 era. What's wrong with using the FF ActiveX code? I believe you. I'm just curious why. Looks like code checked in on Jun 2010, so it looks maintained....

  9. #9
    PowerPoster
    Join Date
    Dec 2004
    Posts
    24,377

    Re: Convert VBA code calling IE to VBA code calling FireFox?

    i did run some trials with the firefox activex some time ago. without much success

    this has been discussed a few times on the vb6 forum, do a search there

    Is there any device, activeX or not, that I can use to open a web site and then close the device, or change the
    web site, an hour later?
    you can use windows APIs, but i am not sure of the necessary code, i am sure there will be some example in this or the vb6 forum
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  10. #10
    Addicted Member
    Join Date
    Sep 2006
    Posts
    218

    Re: Convert VBA code calling IE to VBA code calling FireFox?

    Hmmm. I actually found the FF ActiveX lib through Googling, but I didn't spend much time reading. I really like the idea of COMifying applications. It could put VBA kinda sorta on equal footing with things like Python or Perl, which have tremendous libraries to do just about anything. I'm not an expert on the subject, but I do have some experience writing COM libraries when I wrote an interface between a genetic/evolutionary algorithm named GALib and VBA. If I can find time between work and changing diapers I'll take a look at the source code to see if any of it makes sense to me. I'm not a quant developer anymore, but Excel/VBA is still my go-to application for work and personal projects. If I get anywhere, I'll post my findings.

  11. #11

    Thread Starter
    Lively Member Emeroogork's Avatar
    Join Date
    Mar 2011
    Location
    Connecticut
    Posts
    102

    Re: Convert VBA code calling IE to VBA code calling FireFox?

    I guess I didn't hit <submit> for my most recent post so I will try to enter it again. Forgive me if it is duplicated.

    As indicated in my original post, I have 3 of 8 URLs that work when called in IE through VBA.
    How would I find out what switches/code/settings I need in VBA to run the three that fail?

    The ambition to use the Firefox ActiveX option apparently is not going to apply
    so I guess I have to stay with IE ):

  12. #12
    PowerPoster
    Join Date
    Dec 2004
    Posts
    24,377

    Re: Convert VBA code calling IE to VBA code calling FireFox?

    How would I find out what switches/code/settings I need in VBA to run the three that fail?
    do they open in you put the url into ie browser window?

    as these problem seem to be os and browser version issues, plus possibly whether adobe is installed and up to date, no one can really test for you

    there have, recently, been some threads in vb6 forum about forcing which version of ie to use when using webbrowser control, this might have some relevance, making sure the latest version of ie is used

    you may even need to update your ie installation, and or flash

    even the ones that work for you do not work on my computer in ie 8

    unfortunately the writers of other browsers do not consider the automating of their product (as com objects) for web scraping to be of importance
    Last edited by westconn1; Jul 19th, 2015 at 02:37 AM.
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width