PDA

View Full Version : Reading values from a closed excel sheet



sathishesb
07-20-2011, 02:56 AM
Hi guys,

Can you please help me out with some sample code, how to access a closed excel file from a particular folder using vba code.

My consern is everytime i need to open a differet closed excel.

:help

sathishesb
07-20-2011, 03:21 AM
please some one help me..
it's urgent :dunno

Kenneth Hobs
07-20-2011, 04:14 AM
You should allow time for an answer. If you bump your post, it may not be seen as a 0 response will get more attention. You can bump if more than 1 day has passed.

To get one value:
Sub t()
MsgBox GetInfoFromClosedFile(ThisWorkbook.path, ThisWorkbook.Name, "Sheetx", "A1")
MsgBox Workbooks(ThisWorkbook.path & "\PageSetup2.xls").Name
End Sub

Private Function GetInfoFromClosedFile(ByVal wbPath As String, _
wbName As String, wsName As String, cellRef As String) As Variant
Dim arg As String
GetInfoFromClosedFile = ""
If Right(wbPath, 1) <> "\" Then wbPath = wbPath & "\"
If Dir(wbPath & "\" & wbName) = "" Then Exit Function
arg = "'" & wbPath & "[" & wbName & "]" & _
wsName & "'!" & Range(cellRef).Address(True, True, xlR1C1)
On Error Resume Next
GetInfoFromClosedFile = ExecuteExcel4Macro(arg)
End Function

sathishesb
07-20-2011, 04:27 AM
Ok Thanks a lot..