Excel VBA table query to get connection url from cell or more specific in data validation list

huuhkaaja

New Member
Joined
Aug 9, 2014
Messages
5
Below is my code, but what I need is VBA to get a part of the connection url from a cell.
I've got a list of IDnumbers f.ex. 12345, 23456, 34567 etc. in cell "B7" and I need the connection url to be formed like ->

http://www.eliteprospects.com/player.php?player= & "IDnumber". The IDnumbers are in a data validation list and I need excel/VBA get that number and put it after the "XXXXXphp?player=" to refresh the query every time that number is changed.

If that isn't possible i've got also a list of full url's so forming that connection url from two parts is not mandatory. Only thing that is mandatory is to get the connection url from a data validation list as a whole or combined from different cells.

And please dont tell me to create .iqy files as they are not working. And if someone gives me a string of code to get the iqy-files to work perfectly, that would force me to create like 1500 different iqy's and that is something i wont do.

The only way I can get Excel to import the right tables is VBA table query. The tables are "dynamically scripted" so Excel's web query browser does NOT import those tables. Also tried and tested iqy-files and they perform exactly like web query browser and imports nothing I ask it to.


My code:

Sub Basic_Web_Query()


Application.Wait (Now + TimeValue("0:00:01"))


With ActiveSheet.QueryTables.Add(Connection:= _
"URL;http://www.eliteprospects.com/team.php?team=43", Destination:=Range("$A$1"))
.Name = "q?s=goog_2"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlOverwriteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingAll
.WebTables = "14"
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = True
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With


End Sub
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
You can build the URL using concatenation, eg:

Rich (BB code):
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;http://www.eliteprospects.com/team.php?team=" & Range("B7").Value, Destination:=Range("$A$1"))
 
Upvote 0
I REALLY appreciate this. It works perfectly.

But I really dont understand why this solution has not worked before. I've tried that dozens of times but it never worked before. :) Maybe I had a minor error in the code before.

Thank you!
 
Upvote 0

Forum statistics

Threads
1,215,982
Messages
6,128,104
Members
449,421
Latest member
AussieHobbo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top