PDA

View Full Version : Solved: Excel ADODB worksheet



artrookie
12-11-2008, 12:52 AM
Hi everyone

I have question on ADODB and VBA, was wondering whether there was a way to have a variable worksheet name using ADODB. I am quite new to using ADODB could not find the answer on the web

sSQL = "SELECT * FROM [WORKSHEET$A1:gL1000]"

So, for the code above WORKSHEET is a reference to another worksheet name. So WORKSHEET maybe "WS1" or "WS2" rather then grab data from sheet called "WORKSHEET" (i hope that makes sense)?

Thanks

artrookie

Jan Karel Pieterse
12-11-2008, 01:14 AM
Put the sheet name in a variable called sSheetName and use that:

sSheetName = "Sheet29"
sSQL = "SELECT * FROM [" & sSheetName & "!$A1:gL1000]"

Note that I added an exclamation mark, but maybe it isn't needed in this SQL statement.

artrookie
12-11-2008, 01:23 AM
It works - thanks for quick reply :)