Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 280
Default 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?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 280
Default 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?





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 64
Default 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?






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default 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?







  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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?







Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Retrieving Data in excel Siddarth Jain Excel Worksheet Functions 1 November 13th 07 10:24 AM
retrieving data Jess Excel Worksheet Functions 1 February 13th 07 04:54 PM
Retrieving SQL data into Excel Rob Setting up and Configuration of Excel 1 June 27th 06 11:18 PM
Retrieving data from the web - help ! glynny Excel Worksheet Functions 0 February 20th 06 02:04 AM
Retrieving external data Ryan Excel Programming 0 February 20th 04 07:24 PM


All times are GMT +1. The time now is 10:11 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"