LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 70
Default Import data from a closed workbook

Hello all-

I have an opened workbook that needs to pull data from a closed workbook.
Does anyone have a macro that can pull data from the closed workbook and
import it into the opened workbook? I don't know how many rows of data
there are, but there are always 4 columns. I am currently using the code
below, but it only pulls 100 rows of data. I need a macro that will pull
tdata from the last used row. Can any tweak the code or maybe have a better
one? Thanks

Sub Retrieve_Info()
P = "C:\Documents and Settings\David Truong\Desktop"
f = "Book2.xlsm"
s = "Sheet1"

Application.ScreenUpdating = False
For r = 1 To 100
For c = 1 To 3
a = Cells(r, c).Address
Cells(r, c) = GetValue(P, f, s, a)
Next c
Next r
Application.ScreenUpdating = True
End Sub


Private Function GetValue(path, file, sheet, ref)
' Retrieves a value from a closed workbook
Dim arg As String


' Make sure the file exists
If Right(path, 1) < "\" Then path = path & "\"
If Dir(path & file) = "" Then
Exit Function
End If

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

' Execute an XLM macro
GetValue = ExecuteExcel4Macro(arg)
End Function

 
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
Using Closed Workbook as Data Book DarnTootn Excel Discussion (Misc queries) 5 March 13th 07 09:51 PM
CAN I IMPORT DATA FROM A CLOSED FILE TO A NEW WORKSHEET Paul Excel Discussion (Misc queries) 1 January 11th 07 02:30 PM
How do I import data from a closed Excel Spreadsheet? Tomcat Excel Discussion (Misc queries) 2 May 30th 06 12:51 PM
Data Validation From Closed WorkBook TeRex82 Excel Discussion (Misc queries) 2 May 12th 06 10:45 AM
How to extract data from a wooksheet in a closed workbook kuansheng Excel Worksheet Functions 2 February 15th 06 03:46 AM


All times are GMT +1. The time now is 10:48 AM.

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

About Us

"It's about Microsoft Excel"