+ Reply to Thread
Results 1 to 5 of 5

Trouble Checking for Add-in Update

Hybrid View

  1. #1
    Registered User
    Join Date
    12-14-2016
    Location
    London, England
    MS-Off Ver
    2013
    Posts
    3

    Trouble Checking for Add-in Update

    I've written an Add-in in Excel VBA. I'm made a function to check for updates. It uses ie, and looks something like this:

    Public Sub UpdateCheck()
        Dim ie As Object
        Set ie = CreateObject("internetexplorer.application")
        ie.Visible = False
        ie.navigate "https://example.com/checkforupdate"
    
        Do While ie.readystate <> 4: DoEvents: Loop
    
        Set HTML = ie.document
        If HTML.DocumentElement.innerHTML = "update is available" Then
            MsgBox "An update is ready. Go get it!"
        End If
    End Sub
    Now I can test that out by running it manually from the Macro dialog. It works great!

    My problem is, that I want this sub to run automatically whenever Excel runs. I've tried calling it from "Workbook_Open()" in my add-in, but I found that calling it from there prevents the workbook from opening fully. Excel just displays a grey screen. Not sure what's wrong.

    Anyway, when should my update sub get called?

    Thanks!

  2. #2
    Registered User
    Join Date
    12-14-2016
    Location
    London, England
    MS-Off Ver
    2013
    Posts
    3

    Re: Trouble Checking for Add-in Update

    Just to be even more clear, if you create and add-in with this code:

    Private Sub Workbook_Open()
        Call CheckForUpdate
    End Sub
    
    Public Sub CheckForUpdate()
        Dim ie As Object
        Set ie = CreateObject("internetexplorer.application")
        ie.Visible = False
        ie.navigate "https://example.com/checkforupdate"
    
        Do While ie.readystate <> 4: DoEvents: Loop
    
        Set HTML = ie.document
        If HTML.DocumentElement.innerHTML = "update is available" Then
            MsgBox "An update is ready. Go get it!"
        Else
            MsgBox "no update"
        End If
    
        Set ie = Nothing
    End Sub
    Then save it (as add-in .xlam) and activate it. After that I cannot open any Excel files. I just get the message box and then a grey screen. What's going on?

    Also, I'm using Excel 2013 x64.

  3. #3
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Trouble Checking for Add-in Update

    This line does not appear to me as a correct
    If HTML.DocumentElement.innerHTML = "update is available" Then
    I suspect the code is freezing because IE is terribly slow and you should use HTTP request instead

  4. #4
    Registered User
    Join Date
    12-14-2016
    Location
    London, England
    MS-Off Ver
    2013
    Posts
    3

    Re: Trouble Checking for Add-in Update

    Thanks. Can you give me an example of using http request?

  5. #5
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Trouble Checking for Add-in Update

    What do you want to do with code? Here is the bare minimum. It gives you to open and send request. Once you have access, you can play with web page as you do with IE.

    Option Explicit
    
    Sub test()
    Dim HTMLdoc As Object
              With CreateObject("winhttp.winhttprequest.5.1")
                .Open "GET", "https://www.google.com", False
                .send
                If .statusText <> "OK" Then
                
                    MsgBox "ERROR" & .Status & " - " & .statusText, vbExclamation
                    Exit Sub
                    
                End If
                Set HTMLdoc = CreateObject("HTMLfile")
                 HTMLdoc.body.innerHTML = .responseText
                MsgBox HTMLdoc
            End With
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Having Trouble Checking Whether A Folder Exists Using VBA
    By pablowilks in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-13-2016, 10:52 AM
  2. [SOLVED] Trouble with Find Error Checking: Is Nothing and Is Not Nothing returning the same results
    By k64 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-24-2013, 09:02 PM
  3. [SOLVED] Checking 2 values to update a cell
    By NeoFlex in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 07-01-2013, 09:31 AM
  4. Help with formula for checking most recent update
    By neilwilson in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 12-06-2012, 02:12 AM
  5. Trouble with If and checking same values
    By CoffeeAddict in forum Excel General
    Replies: 2
    Last Post: 07-20-2012, 11:00 AM
  6. Replies: 7
    Last Post: 02-05-2012, 06:50 PM
  7. Trouble with multiple IFs/ANDs/ORs checking for content
    By zazu88hike in forum Excel General
    Replies: 4
    Last Post: 03-11-2008, 04:54 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1