Creating dynamic link to web page in Excel

stevesansan

New Member
Joined
Apr 7, 2010
Messages
5
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
 

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
Welcome to the Board.

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

stevesansan

New Member
Joined
Apr 7, 2010
Messages
5
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
 

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
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")
 

stevesansan

New Member
Joined
Apr 7, 2010
Messages
5
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
 

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
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.
 

stevesansan

New Member
Joined
Apr 7, 2010
Messages
5
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;<TABLE style="WIDTH: 67pt; BORDER-COLLAPSE: collapse" border=0 cellSpacing=0 cellPadding=0 width=89><COLGROUP><COL style="WIDTH: 67pt; mso-width-source: userset; mso-width-alt: 3254" width=89><TBODY><TR style="HEIGHT: 15pt" height=20><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: transparent; WIDTH: 67pt; HEIGHT: 15pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" height=20 width=89>http://........../managementreport.aspx?StartDate=2010/03/01&enddate=2010/03/31</TD></TR></TBODY></TABLE>", _
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
 

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
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:

stevesansan

New Member
Joined
Apr 7, 2010
Messages
5
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
 

Forum statistics

Threads
1,082,250
Messages
5,364,020
Members
400,774
Latest member
Goldi paul

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top