barciewicz
barciewicz

Reputation: 3773

Sheets.Count on inactive sheet

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

Answers (1)

Shai Rado
Shai Rado

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

Related Questions