Results 1 to 9 of 9

Thread: Creating dynamic link to web page in Excel
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    New Member
    Join Date
    Apr 2010
    Posts
    5
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Creating dynamic link to web page in Excel

    I am using Excel 2007 on Windows 7 Pro
    I have a spreadsheet which is updated from a website. Presently this works from a permanent URL.
    I am looking to create a dynamic URL whereby Excel will have two cell which represent the start date and end date, which are to form part of the websire URL. (Presently I have to manually change the URL to change the date ranges).
    How do I create the macro and iqy to make the URL dynamic?
    Thanks
    steve

  2. #2
    MrExcel MVP
    Moderator
    Andrew Poulsom's Avatar
    Join Date
    Jul 2002
    Posts
    73,092
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    3 Thread(s)

    Default Re: Creating dynamic link to web page in Excel

    Welcome to the Board.

    What's the URL and which parts do you want to make dynamic using which cells?
    Microsoft MVP - Excel

  3. #3
    New Member
    Join Date
    Apr 2010
    Posts
    5
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Re: Creating dynamic link to web page in Excel

    Hi Andrew
    The end part of URL is as follows:-

    ....\ManagementReport.aspx?startdate=2010/03/01&enddate=2010/03/31

    What I want to achieve is two cells in Excel that have the dates for the "startdate" and "enddate" parameters such that the URL used in the "Get External Data - from Web" reflects this.

    Hope this makes sense

    steve

  4. #4
    MrExcel MVP
    Moderator
    Andrew Poulsom's Avatar
    Join Date
    Jul 2002
    Posts
    73,092
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    3 Thread(s)

    Default Re: Creating dynamic link to web page in Excel

    You can build it up with concatenation like this:

    "....\ManagementReport.aspx?startdate=" & Format(Range("A1").Value, "yyyy/mm/dd") & "&enddate=" & Format(Range("A2").Value, "yyyy/mm/dd")
    Microsoft MVP - Excel

  5. #5
    New Member
    Join Date
    Apr 2010
    Posts
    5
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Re: Creating dynamic link to web page in Excel

    Thanks Andrew for the help
    I now have the URL in a cell in Excel (through the concatenation).

    How do I now automatically get this text into the "Address" box of the "New Web Query" to create access to the External Data?

    Thanks

    steve

  6. #6
    MrExcel MVP
    Moderator
    Andrew Poulsom's Avatar
    Join Date
    Jul 2002
    Posts
    73,092
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    3 Thread(s)

    Default Re: Creating dynamic link to web page in Excel

    You could copy it and paste it into the dialog. But a macro is probably the way to go. Record one and you will get some code you can edit.
    Microsoft MVP - Excel

  7. #7
    New Member
    Join Date
    Apr 2010
    Posts
    5
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy Re: Creating dynamic link to web page in Excel

    Hi Andrew

    Thanks for your perserverance with me!

    I have created the macro and tried it with a static URL - it works:-

    Sub Macro5()
    '
    ' Macro5 Macro
    '
    With ActiveSheet.QueryTables.Add(Connection:= _
    "URL;
    http://........../managementreport.a...ate=2010/03/31
    ", _
    Destination:=Range("a1"))

    .BackgroundQuery = True
    .TablesOnlyFromHTML = True
    .Refresh BackgroundQuery:=False
    .SaveData = True
    End With
    '
    End Sub


    Question - how do I change the URL to be the cell reference which contains my URL?

    Thanks for all your help

    steve

  8. #8
    MrExcel MVP
    Moderator
    Andrew Poulsom's Avatar
    Join Date
    Jul 2002
    Posts
    73,092
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    3 Thread(s)

    Default Re: Creating dynamic link to web page in Excel

    It would be something like:

    Code:
        With ActiveSheet.QueryTables.Add(Connection:= _
            "URL;" & Range("A1").Value, _
            Destination:=Range("a1"))
    or:

    Code:
        With ActiveSheet.QueryTables.Add(Connection:= _
            "URL;http://........../managementreport.aspx?StartDate=" & Format(Range("A1").Value, "yyyy/mm/dd") & "&enddate=" & Format(Range("A2").Value, "yyyy/mm/dd"), _
            Destination:=Range("a1"))
    Change the range references to suit.
    Last edited by Andrew Poulsom; Apr 7th, 2010 at 09:31 AM.
    Microsoft MVP - Excel

  9. #9
    New Member
    Join Date
    Apr 2010
    Posts
    5
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile Re: Creating dynamic link to web page in Excel

    Hi Andrew

    It all works!

    Thanks for all your help and support - I would not have got the solution without your expertise

    kind regards
    steve

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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