How to add a wildcard to a URL in VBA?

In the code below, I have multiple versions of the same URL.  I would like to change it to something like this with a wildcard. "https://servman/sm/index.do*"

Sub getIE(ByRef objIE As Object, ByRef blnFoundWebSite As Boolean)
On Error GoTo ErrorRoutine
    Dim strURL      As Variant
    Dim strURLs     As String
    Dim objShell    As SHDocVw.ShellWindows
    Dim objIEDOC    As Object
    
    Set objShell = New SHDocVw.ShellWindows

' **** Set the Web Address Here ****
    strURLs = "https://servman/sm/index.do,https://servman/sm/index.do#,https://servman/sm/index.do?lang=en,https://servman/sm/index.do?lang=en&mode=index.do,https://servman/sm/index.do?lang=en&mode=index.do&logout_msg=LogoutPage.session_timeout"
  
    ' 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
    
    On Error Resume Next
    Set objIE = objIE
    Set objIE = objIE.frames.Item(0)
    Set objIE = objIE.frames.Item(1)
    On Error GoTo 0
    
    
    Set objShell = Nothing
    Set objIEDOC = Nothing
    
Exit Sub
ErrorRoutine:

End Sub

Open in new window

kbay808Asked:
Who is Participating?
 
NorieVBA ExpertCommented:
You could try changing this to look for a partial match instead of an exact match.

  If objIEDOC.URL = strURL Then

Open in new window

Perhaps something like this where strURL contains the 'base' URL.
  If objIEDOC.URL Like strURL & "*" Then 

Open in new window

0
 
Fabrice LambertFabrice LambertCommented:
Then what do you want to do with the wildcard ?
Replace it with various values ?

If so, it is better to have a base URL (constant if possible), and concatenate the different values later.
0
 
kbay808Author Commented:
All of the URLs start with "https://servman/sm/index.do".  It doesn't matter what comes after it.
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

 
NorieVBA ExpertCommented:
You can't use a wildcard in a URL to navigate to a site.

Do you have a list of possible values, or perhaps some sort of string pattern that could come after the 'base' URL https://servman/sm/index.do?

What do you see if you navigate to https://servman/sm/index.do?
0
 
kbay808Author Commented:
Just to clarify, the code does not open the URL.  It's just searching IE for one that is already open.
0
 
Fabrice LambertFabrice LambertCommented:
Hmm, having a code that open the same web page with various parameters at the same time.... suspicious if you ask me.
0
 
kbay808Author Commented:
It's not opening it.  The web page is already open.  I just need to target it to click buttons and input data.
0
 
kbay808Author Commented:
That worked perfect!!!  Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.