I found the below code online for copying data from a closed workbook to my currently open file, couple of issues that I would like to get help with.
•Data is copied okay but when pasting into A1:D6 it pastes the same data in every cell
•I need it to copy/paste exactly from the original data, could be numbers, text, or general formatted data.
Thanks
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
GetValue = "File Not Found"
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
Sub TestGetValue2()
p = "C:\Excel Test"
f = "Terry 2.xlsx"
s = "Sheet1"
a = "D6:G9"
Range("A1:D6") = GetValue(p, f, s, a)
End Sub
Bookmarks