View Single Post
  #23   Report Post  
Posted to microsoft.public.excel.misc
David T David T is offline
external usenet poster
 
Posts: 70
Default Importing unopened worksheet into an open Workbook

Hey Bob-

The code below works great but since I don't know how much data i have
because people update the worksheet daily, can you modify the code to where
it pulls data from the last used row instead of only 100 rows?

"Bob" wrote:

Hi GrayesGhost

I hope this will help you.

Sub Retrieve_Info
P = "C:\MyDocumnets"
f = "Test.xls"
s = "Sheet1"

Application.ScreenUpdating = False
For r = 1 To 100
For c = 1 To 4
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("A1").Address(, , xlR1C1)

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

Thanks
Bob

"GrayesGhost" wrote:

If an unopened Excel Workbook only contains a single worksheet, is it
possible to import the data from that worksheet into another Workbook that is
open, without having to open the other file?