Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Get Values from Closed Excel

2 views
Skip to first unread message

jm

unread,
Sep 29, 2005, 3:48:04 PM9/29/05
to
I have two excel spreadsheets: test.xls and test2.xls

test.xls has information i want to automatically pull into test2.xls, and I
would like keep test.xls closed during this process. test2.xls will be open
when the command is given.

test.xls has the following characteristics
path: K:\Data Directories\
name: test.xls
sheet: mastedb Query
cells needed: A1:DV126

test2.xls has the follwing characteristics
path: K:\Data Directories\
name: test2.xls
sheet: test
can put data starting at cell: A1

It would be great, because I am an intern and under the gun to figure this
out, if someone could help me write the whole VBA command using the
information that I've placed above. I just can't see where to put
everything, and I keep getting errors. Thank you in advance.

Ron de Bruin

unread,
Sep 29, 2005, 3:59:10 PM9/29/05
to
Why not open it ?

Maybe you can use ADO
http://www.rondebruin.nl/ado.htm


--
Regards Ron de Bruin
http://www.rondebruin.nl


"jm" <j...@discussions.microsoft.com> wrote in message news:A18C9450-34C7-426A...@microsoft.com...

RB Smissaert

unread,
Sep 29, 2005, 4:07:42 PM9/29/05
to
Try this code:

Function GetValueFromWB(path, file, sheet, ref)

'Retrieves a value from a closed workbook
'----------------------------------------
Dim strSep As String
Dim arg As String

strSep = "\"

'Make sure the file exists
'-------------------------
If Right$(path, 1) <> strSep Then path = path & strSep
If bFileExists(path & file) = False Then
GetValueFromWB = "File Not Found"
Exit Function
End If

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

'Execute an XLM macro
'--------------------
GetValueFromWB = ExecuteExcel4Macro(arg)

End Function

Function bFileExists(strFile As String) As Boolean
bFileExists = (Len(Dir(strFile)) > 0)
End Function


RBS


"jm" <j...@discussions.microsoft.com> wrote in message
news:A18C9450-34C7-426A...@microsoft.com...

jm

unread,
Sep 29, 2005, 4:11:12 PM9/29/05
to
can you help me write this code? the test.xls will remain closed during this
process -- that's what my boss wants, so i have to figure out how to do this
with test.xls closed.

so, i need to ask again. can you show me how to write this VBA with the
characteristics that i outline below?

Ron de Bruin

unread,
Sep 29, 2005, 4:16:04 PM9/29/05
to
You can download the Example zip on the site
The first macro show you how to get information out of the closed file

You can use this code in your test2.xls to get the information

--
Regards Ron de Bruin
http://www.rondebruin.nl


"jm" <j...@discussions.microsoft.com> wrote in message news:5E5ACD9F-5183-4184...@microsoft.com...

jm

unread,
Sep 29, 2005, 4:35:03 PM9/29/05
to
I've seen that code before (or something that looks very similiar)...for the
last three days, I've gone through almost every thread that says "closed
excel" (or the like) -- and my problem is that i have no idea what this stuff
means b/c there is never any good live examples...

it would probably take you or someone else minutes to show me an example
using the information that i have given (see start of thread). it's
frustrating not being able to get something to work, and i'm posting this b/c
i've already been to all the links and have read all the chat rooms...and i'm
at a lost to get it working.

can you help me out with my specific example? it would be greatly
appreciated.

RB Smissaert

unread,
Sep 29, 2005, 5:27:26 PM9/29/05
to
OK, if I take you exact example (apart from the path):

Sub testing()

Dim arr

arr = GetValueFromWB("C:\", _
"test.xls", _
"mastedb Query", _
Range(Cells(1), Cells(126, 126)).Address)

Range(Cells(1), Cells(126, 126)) = arr

End Sub

I have tested this and it work fine.

RBS

"jm" <j...@discussions.microsoft.com> wrote in message

news:4268C88D-096D-43CE...@microsoft.com...

RB Smissaert

unread,
Sep 29, 2005, 5:43:40 PM9/29/05
to
To deal with your sheet test as well in the open workbook:

Sub testing()

Dim arr

arr = GetValueFromWB("C:\", _
"test.xls", _
"mastedb Query", _
Range(Cells(1), Cells(126, 126)).Address)

With Sheets("test")
Range(.Cells(1), .Cells(126, 126)) = arr
End With

End Sub


RBS


"jm" <j...@discussions.microsoft.com> wrote in message

news:4268C88D-096D-43CE...@microsoft.com...

0 new messages