Syntax for using the full path to get a value

  • Thread starter Thread starter Tommy Flynn
  • Start date Start date
T

Tommy Flynn

I'm almost there, but I just can't get it quit right. I am try to get a
value from a cell using the full path to the file. This ain't working, but
it's close. What am I doing wrong?

Sub Test()
pName = "U:\ExcelFiles\ADI-JournalEntries\Current_Month\Advance-O&M_Cur.xls"
MsgBox pName & Sheets("Journal1").Range("R22")
End Sub
 
Excel VBA doesn't support linking to closed workbooks like excel itself
does. John Walkenbach has documented a method that uses and Excel 4 macro
to in VBA to do this.

http://j-walk.com/ss/excel/tips/tip82.htm

you can possibly use ADO, but that would seem more appropriate for a data
table.

http://www.erlandsendata.no/english/vba/adodao/

Andy Wiggins recently suggest sql.request

This might be a help for getting data to and from Excel and Access: It
includes examples of using variables in SQL queries.
http://www.bygsoftware.com/examples/sql.html

Or you can get there from the "Excel with Access Databases" section on page:
http://www.bygsoftware.com/examples/examples.htm

It demonstrates how to use SQL in Excel's VBA to:

* create a database,
* create a table and add data to it,
* select data from a table,
* delete a table,
* delete a database.

You can also download the demonstration file called "excelsql.zip".

The code is open and commented.


--

Regards
Andy Wiggins
www.BygSoftware.com
===========================
 
Thanks. I'll take a look.

Tommy Flynn

Tom Ogilvy said:
Excel VBA doesn't support linking to closed workbooks like excel itself
does. John Walkenbach has documented a method that uses and Excel 4 macro
to in VBA to do this.

http://j-walk.com/ss/excel/tips/tip82.htm

you can possibly use ADO, but that would seem more appropriate for a data
table.

http://www.erlandsendata.no/english/vba/adodao/

Andy Wiggins recently suggest sql.request

This might be a help for getting data to and from Excel and Access: It
includes examples of using variables in SQL queries.
http://www.bygsoftware.com/examples/sql.html

Or you can get there from the "Excel with Access Databases" section on page:
http://www.bygsoftware.com/examples/examples.htm

It demonstrates how to use SQL in Excel's VBA to:

* create a database,
* create a table and add data to it,
* select data from a table,
* delete a table,
* delete a database.

You can also download the demonstration file called "excelsql.zip".

The code is open and commented.


--

Regards
Andy Wiggins
www.BygSoftware.com
===========================
 
I did a work-a-round. It's not rocket science, but it works.

Sub GetValue()
Dim myRng As Range
Set myRng = Sheets(2).Range("A1")
If myRng.HasFormula Then
myVar = myRng.Formula
Else
myVar = myRng.Value
End If
myRng.Formula =
"='U:\ExcelFiles\ADI-JournalEntries\Current_Month\[Advance-O&M_Cur.xls]Journ
al1'!$R$22"
MsgBox Format(myRng, "###,###.#0")
myRng = myVar
End Sub

Thanks for your help.

Tommy
 
Back
Top