Replacing hard code with reference to a cell value

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

Currently I am using the following line of code to specify the location of
my database.

MyConn = "S:\Mydatabase.mdb"

Instead of hard coding the location of my database, I would like to enter
the location in Cell A1 in Sheet2. How do I change this line of code so it
would read the location of my database from whatever I type into cell A1 in
Sheet2?

Thanks!
 
myConn = activeworkbook.worksheets("sheet2").range("a1").value

Activeworkbook
could be
ThisWorkbook
if the that worksheet is in the same workbook with the code.

Or even
workbooks("myotherworkbook.xls").worksheets("sheet2").range("a1").value
 
thank you!

Dave Peterson said:
myConn = activeworkbook.worksheets("sheet2").range("a1").value

Activeworkbook
could be
ThisWorkbook
if the that worksheet is in the same workbook with the code.

Or even
workbooks("myotherworkbook.xls").worksheets("sheet2").range("a1").value
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top