How to change a vba code that runs on 1 url to run on multiple urls?

The target url for this code is “https://servman/sm/index.do”, but I need it to run on “https://servman/sm/index.do2” and “https://servman/sm/index.do3” to.

Sub Paste_Journal()
Dim objIE As SHDocVw.InternetExplorer
    Dim objShell As SHDocVw.ShellWindows
    Dim objIEDoc As MSHTML.HTMLDocument
    Dim objFound As MSHTML.HTMLBaseElement
    Dim strURL As String
    Dim blnFoundWebSite As Boolean
    Dim objDialog As FileDialog
    Dim objFSO As Scripting.FileSystemObject
    Dim objText As Scripting.TextStream
    Dim objDebugFile As Scripting.TextStream
    
    Dim varFrame As Variant
    Dim varFrame2 As Variant
    Dim objFrameDoc As MSHTML.HTMLDocument
    Dim objFrameDoc2 As MSHTML.HTMLDocument
    Dim i As Integer
    Dim j As Integer
    
    Dim objElem As MSHTML.HTMLBaseElement
    Dim objElemDoc As MSHTML.HTMLDocument
    Dim objElem2 As MSHTML.HTMLBaseElement
    Dim objElemDoc2 As MSHTML.HTMLDocument

        
    Set objShell = New SHDocVw.ShellWindows
    Set objFSO = New Scripting.FileSystemObject
    On Error Resume Next
    
    ' **** Set the Web Address Here ****
    strURL = "https://servman/sm/index.do"
    
    
    
    ' Look for the appropriate open IE Window
    For Each objIE In objShell
        If TypeOf objIE.Document Is MSHTML.HTMLDocument Then
            Set objIEDoc = objIE.Document
            If Not (objIEDoc Is Nothing) Then
                If objIEDoc.URL = strURL Then
                    blnFoundWebSite = True
                    Exit For
                End If
            End If
        End If
    Next
    
    Set objFrameDoc2 = objIEDoc

    If blnFoundWebSite Then
        ' Make sure IE is done loading the page
        Do Until Not objIE.Busy
            DoEvents
        Loop
        
        ' Make Sure we had some frames returned
        If objIEDoc.frames.Length > 0 Then
            ' Get the Document from the 1st Frame
            Set varFrame = objIEDoc.frames.Item(0)
            Set objFrameDoc = varFrame.Document
            
            ' Get the Detail Frame (Sub Frame #2)
            If objFrameDoc.frames.Length > 1 Then
                Set varFrame2 = objFrameDoc.frames.Item(1)
                Set objFrameDoc2 = varFrame2.Document
                
                'Journal Updates
                Set objFound = objFrameDoc2.getElementById("X161")
                If objFound Is Nothing Then
                    Range("A3").Value = ""
                Else
                    Range("A3").Value = objFound.Value
                End If
                             
                Set objFound = objFrameDoc2.getElementById("X154")
                If objFound Is Nothing Then
                    Range("A3").Value = ""
                Else
                    Range("A3").Value = objFound.Value
                End If
                
            Else
                            
                'Journal Updates
                Set objFound = objFrameDoc.getElementById("X161")
                If objFound Is Nothing Then
                    Range("A3").Value = ""
                Else
                    Range("A3").Value = objFound.Value
                End If
                
                Set objFound = objFrameDoc.getElementById("X154")
                If objFound Is Nothing Then
                    Range("A3").Value = ""
                Else
                    Range("A3").Value = objFound.Value
                End If
                
                
            End If ' objFrameDoc.frames.Length > 1
        End If ' objIEDoc.frames.Length > 0
        
        Range("A3").Font.Color = RGB(0, 0, 0)
        
        
    End If
    
    
    Set objIE = Nothing
    Set objShell = Nothing
    Set objIEDoc = Nothing
    Set objIEDoc = Nothing
    Set objFound = Nothing
    Set objDialog = Nothing
    Set objFSO = Nothing
    Set objText = Nothing
    Set objDebugFile = Nothing
    
End Sub

Open in new window

kbay808Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rgonzo1971Commented:
Hi,

You can use to loop through the url
    strURLS = "https://servman/sm/index.do,https://servman/sm/index.do2,https://servman/sm/index.do3"
    
    For Each strURL In Split(strURLS, ",")

    Next

Open in new window

But you dont say where should go the new info

Regards
kbay808Author Commented:
I could not get your code to work.  The only way that I can make it the original code to work for all 3 is to list the full code in 3 different macros with each one with a different web address.   I’m trying to shrink that down.
kbay808Author Commented:
The issue that I have is that the URL for the web site that I’m extracting data from can change in to one of the 3 examples listed.  I’m trying to make the code work regardless of which of the 3 URLs it is and ignoring the other 2 URLs.
OWASP Proactive Controls

Learn the most important control and control categories that every architect and developer should include in their projects.

Rgonzo1971Commented:
Hi,

pls try
strURLS = "https://servman/sm/index.do,https://servman/sm/index.do2,https://servman/sm/index.do3"
Res = InputBox("Which URL do you want to use?" & vbCrLf & _
        "1 for 'https://servman/sm/index.do'" & vbCrLf & _
        "2 for 'https://servman/sm/index.do2'" & vbCrLf & _
        "3 for 'https://servman/sm/index.do3'", "Choose URL")
If Res > 0 And Res < 4 Then
    strURL = Split(strURLS, ",")(Res - 1)
Else
Exit Sub
End If

Open in new window

Regards
kbay808Author Commented:
That works, but the use has to pick the url each time that they run the macro which is a lot.  I’m trying to automate it so that the macro tries the 1st ulr and if not detected, then try the 2nd and then the 3rd.  When a url is detected, then skip any remaining urls.

This is what I had in mind, but can figure out how to do it.

On error goto url2
url 1
If found goto code

url2:
On error goto next url3
url 2
If found goto code

url3:
On error end sub
url 3

My code
Rgonzo1971Commented:
pls try

    strURLS = "https://servman/sm/index.do,https://servman/sm/index.do2,https://servman/sm/index.do3"
  
    ' Look for the appropriate open IE Window
    For Each objIE In objShell
        If TypeOf objIE.Document Is MSHTML.HTMLDocument Then
            Set objIEDoc = objIE.Document
            If Not (objIEDoc Is Nothing) Then
                for each strURL in Split(strURLS, ",")
                    If objIEDoc.URL = strURL Then
                        blnFoundWebSite = True
                        Exit For
                    End If
                Next
                If blnFoundWebSite = True Then Exit For
            End If
        End If
    Next

Open in new window

kbay808Author Commented:
I got an error.  I attached a screen shot of the error and the debug in the background.
ScreenShot.jpg
Rgonzo1971Commented:
Change

 Dim strURL As String

to

Dim strURL As Variant

Regards

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
kbay808Author Commented:
That work!!!  Thank you very much.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.