How to properly append an Excel variable at the end of URL address?

Muir2014

New Member
Joined
Feb 20, 2014
Messages
22
I have a VBA code using QueryTables, that have a URL as String--> exm: "http://homefold/exp/myFile.php" also have variable "hDate" as string having a date value. I need to add that variable at the end of the URL, seams that the task should be easy however I haven't found the solution. The result on sheet is something like : <b>Fatal error</b>: Function must be a string....... This is what I've tried so far : mURL="http://homefold/exp/myFile.php?hDate="& ws.Range("A1") I had switched the ampersand and the quotation in different positions but no success. Can't see what is wrong yet, need a solid on this one.
 
Upvote 0

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Then for that I a grabbed the value for an already format cell to general with value to 20220726, put it in variable string hDate, still the issue, which brings me the previous question, is that if I am paraphrasing the URL correctly, the URL supplied was "http://homefold/exp/MyFile.php" and I'm paraphrasing it like "http://homefold/exp/MyFile.php?hDate="& nDate.

Is that line syntax correct?
It looks like now is working. As you suggested, I first formatted that date cell as "General", then I grab that value, put it in a variable as String, and with that URL syntax mentioned before is working! Thx a bunch !
 
Upvote 0
Well, I didn't notice it originally but your URL is invalid. There is no top-level domain name. When testing code to go to a URL it is always a good idea to test the URL that your code generates and put it right into a browser.

What happens when you put this in a browser:

http://homefold/exp/MyFile.php?hDate=20220726

For me it fails in a browser because homefold is not a valid domain name. It needs to be homefold.com or whatever.
 
Upvote 0
You can't do that. If you declare hDate as a String you can't treat it first as a date

Well, I didn't notice it originally but your URL is invalid. There is no top-level domain name. When testing code to go to a URL it is always a good idea to test the URL that your code generates and put it right into a browser.

What happens when you put this in a browser:

http://homefold/exp/MyFile.php?hDate=20220726

For me it fails in a browser because homefold is not a valid domain name. It needs to be homefold.com or whatever.
The URL I supply in the post does not really exist, but is a replica of the original URL I'm working with, which belongs to a network, I forgot to mention that. Thanks for the help.
 
Upvote 0

Forum statistics

Threads
1,215,494
Messages
6,125,145
Members
449,207
Latest member
VictorSiwiide

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