RzzB
asked on
Getting external worksheets into ThisWorksheet
Using Windows 7 Home (64bit) - Office 365 (32bit)
I have read many posts on this subject but they don't seem to fit my situation exactly.
I have a WorkBook running the code - it has three WorkSheets "Members", "Waiting" and "RenewalDate". They are not contiguous - there are other worksheets.
I have an external WorkBook that also has three WorkSheets with the same names.
There must be a simple way of copying the data from the external worksheets to the local worksheets.
The code I have so far is as follows. the line "ThisWorkbook.Sheets("Memb ers").Cell s.Value = shtData.Cells.Value" causes an "Out of memory" error...
Roy
I have read many posts on this subject but they don't seem to fit my situation exactly.
I have a WorkBook running the code - it has three WorkSheets "Members", "Waiting" and "RenewalDate". They are not contiguous - there are other worksheets.
I have an external WorkBook that also has three WorkSheets with the same names.
There must be a simple way of copying the data from the external worksheets to the local worksheets.
The code I have so far is as follows. the line "ThisWorkbook.Sheets("Memb
Sub GetMembershipData()
Dim strExternalWBPathName As String
Dim xapApp As Excel.Application
Dim wbkMembershipData As Excel.Workbook
Dim shtData As Excel.Worksheet
'Build string and path of external workbook
strExternalWBPathName = ThisWorkbook.Path & "\Data\CFAG Membership Data.xlsx"
'Get a new Application object - because we want to hide the workbook
Set xapApp = CreateObject("Excel.Application")
'Hide the application and any workbooks
xapApp.Visible = False
'Open the workbook
Set wbkMembershipData = xapApp.Workbooks.Open(strExternalWBPathName)
'Get Members Worksheet -----------------------------------------
Set shtData = wbkMembershipData.Worksheets("Members")
'clear internal worksheet
ThisWorkbook.Sheets("Members").Cells.ClearContents
'now copy from
ThisWorkbook.Sheets("Members").Cells.Value = shtData.Cells.Value
'Get Waiting Worksheet -----------------------------------------
Set shtData = wbkMembershipData.Worksheets("Waiting")
'clear internal worksheet
'ThisWorkbook.Sheets("Waiting").Cells.ClearContents
'now copy from external worksheet to this worksheet
ThisWorkbook.Sheets("Waiting").Cells.Value = shtData.Cells.Value
'Get RenewalData Worksheet -----------------------------------------
Set shtData = wbkMembershipData.Worksheets("RenewalData")
'clear internal worksheet
'ThisWorkbook.Sheets("RenewalData").Cells.ClearContents
'now copy from external worksheet to this worksheet
ThisWorkbook.Sheets("RenewalData").Cells.Value = shtData.Cells.Value
Set shtData = Nothing
wbkMembershipData.Close True 'Close and save the workbook
Set wbkMembershipData = Nothing
xapApp.Quit 'Close the instance of Excel we create
Set xapApp = Nothing
End Sub
Any pointers would be most appreciated.Roy
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I would copy the data from the external sheets and paste to the corresponding sheets. A little more info on what you are doing would help with a different approach - where are the external workbooks, what to copy etc. Maybe an example of the master workbook and sample of the data import
ASKER
Thank for your help. See other post for info on what I'm doing.
https://www.experts-exchange.com/questions/28836959/Complications-Interactions-with-other-WorkBooks.html
https://www.experts-exchange.com/questions/28836959/Complications-Interactions-with-other-WorkBooks.html
ASKER
After a little research I found out about "UsedRange". So the code I'm using now is...
Open in new window
Many thanks for your help.
Roy