none
How to construct URL for iterative web queries if the URL has a variable in the middle of itself? RRS feed

  • Question

  • Question: how to construct URL for iterative web queries if the URL has a variable in the middle of itself?

    I want to do a task of iterative web queries.

    Here is the targeted URL. http://www.osha.gov/pls/imis/sic_manual.display?id=1&tab=group

    You can see "id=1" part (bold) in the URL, and the "1" is the part for iteration. (From 1 to 82)

    The other part of the URL is always the same, but only "1" is different for each iteration.

    So, I coded using a variable "idNum" for "1" part and a command ".Connection = "URL;....."".

    But the problem here is how to construct URL if it has a variable in the middle of itself. I coded like this: .Connection = "URL;http://www.osha.gov/pls/imis/sic_manual.display?id" & idNum & "&tab=group", but as expected it didn't work at all. The last part <& "&tab=group"> was ignored.

    I ask you a help for this problem (how to construct URL if it has a variable in the middle of itself?).

    Thank you very much.

    Wednesday, April 17, 2013 2:54 AM

All replies

  • It is not clear how you are using this, however the following VBA code will open the various web pages, so may point a way forward:

    Option Explicit
    Public pWebAddress As String
    Public i as long
    Public 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

    Public Sub NewShell(cmdLine As String, lngWindowHndl As Long)
        ShellExecute lngWindowHndl, "open", cmdLine, "", "", 1
    End Sub

    Public Sub TestBrowser()
        For i = 1 To 3 '82
            pWebAddress = "http://www.osha.gov/pls/imis/sic_manual.display?id=" & i & "&tab=group"
            Call NewShell(pWebAddress, 3)
        Next i
    End Sub


    Graham Mayor - Word MVP
    www.gmayor.com

    Wednesday, April 17, 2013 5:31 AM