Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default Retrieving a range of values from a closed file

I would like to post a range of values from a closed file on the same drive without opening the closed file. I need the values of ranges B10:B20, B30:B40, D10:D20, and D30:D40 in the closed file to be posted in the same ranges of my open file. Let's call the open file "Apples" and the closed file "Oranges." I cannot use the usual links because I don't want to be prompted about updating links when I open the "Apples" file. If it is only a matter of preventing the update prompt, that would be very acceptable. Can you offer a solution? Thanks.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 538
Default Retrieving a range of values from a closed file

michaelrlanier wrote:

I would like to post a range of values from a closed file on the same
drive without opening the closed file. I need the values of ranges
B10:B20, B30:B40, D10:D20, and D30:D40 in the closed file to be posted
in the same ranges of my open file. Let's call the open file "Apples"
and the closed file "Oranges." I cannot use the usual links because I
don't want to be prompted about updating links when I open the "Apples"
file. If it is only a matter of preventing the update prompt, that would
be very acceptable. Can you offer a solution? Thanks.


In order to get the information out of the workbook, *something* has to open
it *somehow* (unless you want to get *really* low-level and read the data
directly off the hard drive -- a non-trivial task). The easiest way is to
just open it in Excel and not update the links:
Set foo = Workbooks.Open("Oranges", 2)
....or *always* update the links:
Set foo = Workbooks.Open("Oranges", 3)

Look up Worbooks.Open in the help file for more info.

(Assigning to a variable makes it easier close the workbook when you're done
with it:
foo.Close False
"False" here prevents the workbook from saving when it's closed.)

--
I'm whatever you don't want me to be.
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default Retrieving a range of values from a closed file

Thanks Auric and Gary. I'll check out both your suggestions.

Michael
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default Retrieving a range of values from a closed file

On Sep 23, 3:55*pm, wrote:
I would like to post a range of values from a closed file on the same drive without opening the closed file. I need the values of ranges B10:B20, B30:B40, D10:D20, and D30:D40 in the closed file to be posted in the same ranges of my open file. Let's call the open file "Apples" and the closed file "Oranges." I cannot use the usual links because I don't want to be prompted about updating links when I open the "Apples" file. If it is only a matter of preventing the update prompt, that would be very acceptable. Can you offer a solution? Thanks.


You could also try using the old ExecuteExcel4Macro, with code like
this:

Function GetValuesFromWB(vPath, vFile, vSheet, vRef) As Variant

Dim c As Long
Dim r As Long
Dim vArr As Variant
Dim strArg As String
Dim lRows As Long
Dim lCols As Long

If Right$(vPath, 1) < "\" Then
vPath = vPath & "\"
End If

If bFileExistsVBA(vPath & vFile) = False Then
GetValuesFromWB = "File Not Found"
Exit Function
End If

strArg = "'" & vPath & "[" & vFile & "]" & vSheet & "'!" & _
Range(vRef).Range("A1").Address(, , xlR1C1)

lRows = Range(vRef).Rows.Count
lCols = Range(vRef).Columns.Count

If lRows = 1 And lCols = 1 Then
GetValuesFromWB = ExecuteExcel4Macro(strArg)
Else
ReDim vArr(1 To lRows, 1 To lCols) As Variant
For r = 1 To lRows
For c = 1 To lCols
vArr(r, c) = ExecuteExcel4Macro("'" & vPath & "[" & vFile &
"]" & _
vSheet & "'!" & _
Range(vRef).Cells(r,
c).Address(, , xlR1C1))
Next c
Next r
GetValuesFromWB = vArr
End If

End Function

Function bFileExistsVBA(ByVal sFile As String) As Boolean

Dim lAttr As Long

On Error Resume Next
lAttr = GetAttr(sFile)
bFileExistsVBA = (Err.Number = 0) And ((lAttr And vbDirectory) = 0)
On Error GoTo 0

End Function

Sub Test()

Dim v As Variant

v = GetValuesFromWB("C:\testing\", "GetValuesTest.xls", "Sheet1",
"B2:C3")

Cells.Clear
Range(Cells(2), Cells(2, 3)) = v

End Sub


RBS


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default Retrieving a range of values from a closed file

Thanks Bart. You've obviously put some time into your response. This is much appreciated.
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default Retrieving a range of values from a closed file

On Sep 24, 2:42*pm, wrote:
Thanks Bart. You've obviously put some time into your response. This is much appreciated.


No trouble, see if it suits your needs.
One thing is that empty cells will produce a zero and not sure that
can be avoided.

RBS
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
write cell values to a closed file Dave[_11_] Excel Programming 1 August 26th 09 09:54 PM
Error retrieving data from closed workbook Add Excel Programming 4 December 26th 07 03:59 AM
Retrieving values from a specified sheet of a different file. Anift Excel Worksheet Functions 2 April 3rd 06 02:38 PM
How can I add values to a closed excel file? Ali Excel Worksheet Functions 8 June 11th 05 01:13 AM
Getting values from a closed file Shelley[_2_] Excel Programming 2 November 21st 03 07:50 PM


All times are GMT +1. The time now is 05:15 AM.

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"