"Compile error: Expected: expression"

mxaho

New Member
Joined
May 22, 2018
Messages
4
Hi,

This message is coming up and I can't figure out what's wrong, could someone please assist?

qurl = "https://trader.di.se/index.php/stock_history?" & Ticker &
"&startdate=" & MonthName(Month(sdate), True) &
"+" & Day(sdate) & "+" & Year(sdate) & "&enddate=" & Monthname(Month(edate), True) &
"+" & Day(edate) & "+" & Year(edate)

I'm trying to get data from the web to excel.

Thanks in advance!
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Did you try "msgboxing" each variable (sdate, edate, etc) at runtime to make sure it's formatted the way it should be for the URL?

and just to check, this is what I'm seeing for a URL (generically speaking)...

https://trader.di.se/index.php/stock_history?GOOGL&startdate=May+21+2018&enddate=May+22+2018

and BTW, when I try that link it goes to a blank page...forbidden. Could that be the problem? It could be that you are "signing in" elsewhere in the code, just checking everything I can think of....

EDIT: You're putting "+" symbols into your URL and I didn't see any in the one you posted.
 
Last edited:
Upvote 0
You could create string variables to hold the entire date, formatted as you need it and use that in your line of code instead of MonthName....Day...Year. Just another idea.
 
Upvote 0
You could create string variables to hold the entire date, formatted as you need it and use that in your line of code instead of MonthName....Day...Year. Just another idea.

Thans for your answer.

I'm brand new to VBA so that's the big problem haha... The qurl I entered works for me, strange it doens't work for you. As you mentioned, I see that the "+" is wrong (I tried to look at Youtube, but it was another qurl there).

How do I enter a date like "2018-05-22" in the best way in VBA?
 
Upvote 0
I would do something like:

Code:
Dim sdate As String
Dim MyStartDate as String

    sdate = "may 22, 2018"
    
    
   MyStartDate= Format(sdate, "yyyy") & "-" & Format(sdate, "mm") & "-" Format(sdate, "dd")

And then something very similar for MyEndDate...and then:

Code:
qurl = "https://trader.di.se/index.php/stock_history?instrumentid=" & ticker & "&startDate=" & MyStartDate & "&endDate=" & MyEndDate
 
Upvote 0

Forum statistics

Threads
1,214,994
Messages
6,122,633
Members
449,092
Latest member
bsb1122

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