Reputation: 3773
I want my macro to select the last sheet on an inactive workbook "WbCopy", but Sheets.Count works only when the workbook "WbCopy" is active. Do you have any suggestions how to make it work also when the "WbPaste" is active? The code resides in workbook "WbPaste":
Sub CopyPaste()
Dim WbCopy As Workbook
Dim WbPaste As Workbook
Set WbCopy = Workbooks("copy.xlsm")
Set WbPaste = Workbooks("paste.xlsx")
WbCopy.Worksheets(Sheets.Count).Activate
End Sub
Upvotes: 0
Views: 98
Reputation: 33672
Change:
WbCopy.Worksheets(Sheets.Count).Activate
to:
WbCopy.Worksheets(WbCopy.Sheets.Count).Activate
Note: if you have code in WbPaste
, it needs to be .xlsm
extension.
Upvotes: 1