ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   External Cell Reference in VBA? (https://www.excelbanter.com/excel-programming/352301-external-cell-reference-vba.html)

mattsvai[_6_]

External Cell Reference in VBA?
 

I am trying to access a cell in a closed worksheet but I get an
"out of range" error:

Sub import()

Dim var as String
var = Workbooks("file1.xls").Worksheets("Sheet1").Range( "A2").Value
msgbox var

End Sub

Any ideas?

Matt

--
mattsva
-----------------------------------------------------------------------
mattsvai's Profile: http://www.excelforum.com/member.php...fo&userid=3113
View this thread: http://www.excelforum.com/showthread.php?threadid=50810


Tom Ogilvy

External Cell Reference in VBA?
 
You have received extensive answers in other postings of this question.

--
Regards,
Tom Ogilvy

"mattsvai" wrote in
message ...

I am trying to access a cell in a closed worksheet but I get an
"out of range" error:

Sub import()

Dim var as String
var = Workbooks("file1.xls").Worksheets("Sheet1").Range( "A2").Value
msgbox var

End Sub

Any ideas?

Matts


--
mattsvai
------------------------------------------------------------------------
mattsvai's Profile:

http://www.excelforum.com/member.php...o&userid=31134
View this thread: http://www.excelforum.com/showthread...hreadid=508104





All times are GMT +1. The time now is 12:28 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com