Hi all,
I have spent hours searching through past threads to try and come up with a solution but I have failed and I'm not good at VBA. So your help would be greatly appreciated.
I am trying to import a range from a closed workbook into an open workbook.
This is what I have so far:
I expected this to work but I am getting
Run-time error '438':
Object doesn't support this property or method
It is getting as far as opening the workbook and copying the relevant cells but then errors, so doesn't paste those cells into my current workbook.
Any ideas why it's failing?
Following that solution and to take this a stage further, rather than having a set file as wb2, I need to be able to browse to a different file each time. Preferably I would specify a folder in the code and then simply double click on the relevant file. The copied cells will always be the same range.
Can anyone help? Thanks in advance
I have spent hours searching through past threads to try and come up with a solution but I have failed and I'm not good at VBA. So your help would be greatly appreciated.
I am trying to import a range from a closed workbook into an open workbook.
This is what I have so far:
Code:
Sub vbaimport()
' Defines variables
Dim wb1 As Workbook, wb2 As Workbook
' Disable screen updating to reduce screen flicker
Application.ScreenUpdating = False
' Define which workbook is which
Set wb1 = ThisWorkbook
Set wb2 = Workbooks.Open("C:\Users\dan\Documents\Book1.xlsx")
' Copy range A1:A5 from Sheet1 of wb2
wb2.Sheets("Sheet1").Range("A1:A5").Copy
' Paste the copied data to range A1 of the VBAImport sheet in wb1
wb1.Sheets("VBAImport").Range("A1").Paste
' Close wb2
wb2.Close
' Re-enable screen updating
Application.ScreenUpdating = True
End Sub
I expected this to work but I am getting
Run-time error '438':
Object doesn't support this property or method
It is getting as far as opening the workbook and copying the relevant cells but then errors, so doesn't paste those cells into my current workbook.
Any ideas why it's failing?
Following that solution and to take this a stage further, rather than having a set file as wb2, I need to be able to browse to a different file each time. Preferably I would specify a folder in the code and then simply double click on the relevant file. The copied cells will always be the same range.
Can anyone help? Thanks in advance