ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Retrieving data (https://www.excelbanter.com/excel-programming/311499-retrieving-data.html)

Alan M[_2_]

Retrieving data
 
Can i use VBA toretrive data from a workbook that is currently closed and
enter the cell values specified into a range in an open workbook.worksheet
that collates information fromt he ranges in numerous closed workbooks?

Bob Kilmer

Retrieving data
 
To read from or write to a workbook, you must open it. You need not show it,
it can remain invisible to users, but you must open it, and close it when
done.

"Alan M" <Alan wrote in message
...
Can i use VBA toretrive data from a workbook that is currently closed and
enter the cell values specified into a range in an open workbook.worksheet
that collates information fromt he ranges in numerous closed workbooks?




Bob Kilmer

Retrieving data
 
You can open, read and close workbooks programmatically, however, and do
virtually anything that can be done manually with VBA.

"Bob Kilmer" wrote in message
...
To read from or write to a workbook, you must open it. You need not show

it,
it can remain invisible to users, but you must open it, and close it when
done.

"Alan M" <Alan wrote in message
...
Can i use VBA toretrive data from a workbook that is currently closed

and
enter the cell values specified into a range in an open

workbook.worksheet
that collates information fromt he ranges in numerous closed workbooks?






Ajit

Retrieving data
 
Alan,
It's been sort of too late though...but i was trying to find something else
and came across this question.
VBA does not include a method to retrieve a value from a closed workbook
file. You can, however, take advantage of Excel's ability to work with linked
files by using GetValue VBA function that retrieves value from closed
workbook. It does so by calling XML Macro.

Below is the code for finding the value of A1 cell in closed workbook :
abc.xls

Sub TestGetValue()
p = "C:\Documents and Settings\Desktop\ABC"
f = "abc.xls"
s = "Sheet1"
a = "A1"
MsgBox GetValue(p, f, s, a)

End Sub


Private Function GetValue(path, file, sheet, ref)
Dim arg As String
If Right(path, 1) < "\" Then path = path & "\"
If Dir(path & file) = "" Then
GetValue = "File Not Found"
Exit Function
End If

arg = "'" & path & "[" & file & "]" & sheet & "'!" &
Range(ref).Range("A1").Address(, , xlR1C1)

GetValue = ExecuteExcel4Macro(arg)
End Function

Source : John Walkenbach book : Excel 2002 Power Programming with VBA

"Bob Kilmer" wrote:

You can open, read and close workbooks programmatically, however, and do
virtually anything that can be done manually with VBA.

"Bob Kilmer" wrote in message
...
To read from or write to a workbook, you must open it. You need not show

it,
it can remain invisible to users, but you must open it, and close it when
done.

"Alan M" <Alan wrote in message
...
Can i use VBA toretrive data from a workbook that is currently closed

and
enter the cell values specified into a range in an open

workbook.worksheet
that collates information fromt he ranges in numerous closed workbooks?







Delboy

Retrieving data
 
Does anyone know whether the workbook needs to be linked in order to use this
code, or can you just specify the path etc?

"Ajit" wrote:

Alan,
It's been sort of too late though...but i was trying to find something else
and came across this question.
VBA does not include a method to retrieve a value from a closed workbook
file. You can, however, take advantage of Excel's ability to work with linked
files by using GetValue VBA function that retrieves value from closed
workbook. It does so by calling XML Macro.

Below is the code for finding the value of A1 cell in closed workbook :
abc.xls

Sub TestGetValue()
p = "C:\Documents and Settings\Desktop\ABC"
f = "abc.xls"
s = "Sheet1"
a = "A1"
MsgBox GetValue(p, f, s, a)

End Sub


Private Function GetValue(path, file, sheet, ref)
Dim arg As String
If Right(path, 1) < "\" Then path = path & "\"
If Dir(path & file) = "" Then
GetValue = "File Not Found"
Exit Function
End If

arg = "'" & path & "[" & file & "]" & sheet & "'!" &
Range(ref).Range("A1").Address(, , xlR1C1)

GetValue = ExecuteExcel4Macro(arg)
End Function

Source : John Walkenbach book : Excel 2002 Power Programming with VBA

"Bob Kilmer" wrote:

You can open, read and close workbooks programmatically, however, and do
virtually anything that can be done manually with VBA.

"Bob Kilmer" wrote in message
...
To read from or write to a workbook, you must open it. You need not show

it,
it can remain invisible to users, but you must open it, and close it when
done.

"Alan M" <Alan wrote in message
...
Can i use VBA toretrive data from a workbook that is currently closed

and
enter the cell values specified into a range in an open

workbook.worksheet
that collates information fromt he ranges in numerous closed workbooks?






Tom Ogilvy

Retrieving data
 
The workbook does not need to be linked.

the variable p holds the path
--
Regards,
Tom Ogilvy

"Delboy" wrote in message
...
Does anyone know whether the workbook needs to be linked in order to use

this
code, or can you just specify the path etc?

"Ajit" wrote:

Alan,
It's been sort of too late though...but i was trying to find something

else
and came across this question.
VBA does not include a method to retrieve a value from a closed workbook
file. You can, however, take advantage of Excel's ability to work with

linked
files by using GetValue VBA function that retrieves value from closed
workbook. It does so by calling XML Macro.

Below is the code for finding the value of A1 cell in closed workbook :
abc.xls

Sub TestGetValue()
p = "C:\Documents and Settings\Desktop\ABC"
f = "abc.xls"
s = "Sheet1"
a = "A1"
MsgBox GetValue(p, f, s, a)

End Sub


Private Function GetValue(path, file, sheet, ref)
Dim arg As String
If Right(path, 1) < "\" Then path = path & "\"
If Dir(path & file) = "" Then
GetValue = "File Not Found"
Exit Function
End If

arg = "'" & path & "[" & file & "]" & sheet & "'!" &
Range(ref).Range("A1").Address(, , xlR1C1)

GetValue = ExecuteExcel4Macro(arg)
End Function

Source : John Walkenbach book : Excel 2002 Power Programming with VBA

"Bob Kilmer" wrote:

You can open, read and close workbooks programmatically, however, and

do
virtually anything that can be done manually with VBA.

"Bob Kilmer" wrote in message
...
To read from or write to a workbook, you must open it. You need not

show
it,
it can remain invisible to users, but you must open it, and close it

when
done.

"Alan M" <Alan wrote in message
...
Can i use VBA toretrive data from a workbook that is currently

closed
and
enter the cell values specified into a range in an open
workbook.worksheet
that collates information fromt he ranges in numerous closed

workbooks?









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

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