PC Review


Reply
Thread Tools Rate Thread

Retrieving a range of values from a closed file

 
 
michaelrlanier@gmail.com
Guest
Posts: n/a
 
      23rd Sep 2012
I would like to post a range of values from a closed file on the same drivewithout opening the closed file. I need the values of ranges B10:B20, B30:B40, D1020, and D3040 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.
 
Reply With Quote
 
 
 
 
Auric__
Guest
Posts: n/a
 
      23rd Sep 2012
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, D1020, and D3040 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.
 
Reply With Quote
 
 
 
 
GS
Guest
Posts: n/a
 
      23rd Sep 2012
(E-Mail Removed) wrote on 9/23/2012 :
> 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, D1020, and D3040 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 can do this with ADODB. Here's where to start...

http://www.appspro.com/conference/Da...rogramming.zip

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


 
Reply With Quote
 
michaelrlanier@gmail.com
Guest
Posts: n/a
 
      23rd Sep 2012
Thanks Auric and Gary. I'll check out both your suggestions.

Michael
 
Reply With Quote
 
bart.smissaert@gmail.com
Guest
Posts: n/a
 
      24th Sep 2012
On Sep 23, 3:55*pm, michaelrlan...@gmail.com 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, D1020, and D3040 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 promptedabout updating links when I open the "Apples" file. If it is only a matterof 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
 
Reply With Quote
 
michaelrlanier@gmail.com
Guest
Posts: n/a
 
      24th Sep 2012
Thanks Bart. You've obviously put some time into your response. This is much appreciated.
 
Reply With Quote
 
bart.smissaert@gmail.com
Guest
Posts: n/a
 
      24th Sep 2012
On Sep 24, 2:42*pm, michaelrlan...@gmail.com 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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
SUMPRODUCT or SUMIF if any values in a range equal any values in another range PCLIVE Microsoft Excel Worksheet Functions 3 15th Jul 2009 07:43 PM
Retrieving Data: Speed of beating down rows vs retrieving from array? (PeteCresswell) Microsoft Excel Programming 2 9th Jul 2007 03:30 PM
Help with Comparing values and retrieving values in Excel!!!!!! zabedi@gmail.com Microsoft Excel Worksheet Functions 1 17th Nov 2006 01:21 AM
Retrieving range string from named range =?Utf-8?B?Y2xhcHBlcg==?= Microsoft Excel Programming 4 13th Oct 2005 03:09 PM
populate a listbox with values from a range in a closed workbook on a server dovrox Microsoft Excel Misc 1 12th May 2004 02:25 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:27 PM.