Hopefully a basic VBA question, please help!!

mrshl9898

Well-known Member
Joined
Feb 6, 2012
Messages
1,951
Hi,

I have 2 macros, and need to use the IE object in the second macro that is declared and set in the first.

How do I set that up?

Code:
Sub UpdateOwensCards()


    Dim IE As New SHDocVw.InternetExplorer
    Dim IE As New SHDocVw.InternetExplorer
    Dim HTMLdoc As MSHTml.HTMLDocument
    Dim othwb As Variant
    Dim objShellWindows As New SHDocVw.ShellWindows
    Dim rownum As Long
    Dim colnum As Long
    
    rownum = 1
    
Do Until Sheets("Schedules").Cells(rownum, 1).Value = ""
    
    schedID = Sheets("Schedules").Cells(rownum, 1).Value
     
    Set IE = GetObject("new:{D5E8041D-920F-45e9-B8FB-B1DEB82C6E5E}")
    
        With IE
            .Visible = True
            .Navigate "http://maintrakau/Domestic/"
            While .Busy Or .ReadyState <> 4: DoEvents: Wend
        End With


        With IE
            .Visible = True
            .Navigate "http://maintrakau/OnForward/Business/customer_rates.asp?txtScheduleID=" & schedID & "&txtAction=R"
            While .Busy Or .ReadyState <> 4: DoEvents: Wend


                Set HTMLdoc = IE.Document
                ProcessHTMLPage HTMLdoc
                
            .Quit
        End With
   
rownum = rownum + 1


Loop
    
End Sub


Sub ProcessHTMLPage(HTMLPage As MSHTml.HTMLDocument)


    Dim HTMLTable As MSHTml.IHTMLElement
    Dim HTMLTables As MSHTml.IHTMLElementCollection
    Dim HTMLInput As MSHTml.IHTMLElement
    Dim NewCharge As Long
    Dim NewFeeName As String
    Dim foundinput As Long
    
NewCharge = Sheets("Fees").Range("B2").Value
NewFeeName = Sheets("Fees").Range("A2").Value


    Set HTMLTables = HTMLPage.getElementsByTagName("table")
    
    For Each HTMLTable In HTMLTables
    
        If HTMLTable.ID = "tblAdditionalCharges" Then
    
            For Each HTMLInput In HTMLTable.getElementsByTagName("input")
            
                        If foundinput = 1 Then
            
                            Debug.Print HTMLInput.Value
                            Debug.Print NewCharge
                            'HTMLRow.Value = NewCharge
                            'Set Savebtn = IE.Document.getElementById("btnSave")
                            'Savebtn.click
                            'Application.wait (Now + TimeValue("00:00:01"))
                            foundinput = 0
            
                        End If
            
                If HTMLInput.Value Like NewFeeName Then
                
                    foundinput = 1
                    
                End If
        
            Next HTMLInput
    
        End If
    
    Next HTMLTable
   
End Sub
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Where do you need to use the IE object in the second set of code?
 
Upvote 0
Why don't you use HTMLPage?

That's a reference to IE.Document that you are passing from the first procedure to the second and you are using it earlier in the code here.
Code:
HTMLPage.getElementsByTagName("table")
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top