Forum

Excel VBA - Copy Ac...
 
Notifications
Clear all

Excel VBA - Copy Active Sheet to All Open Workbooks

4 Posts
3 Users
0 Reactions
119 Views
(@webbers)
Posts: 147
Estimable Member
Topic starter
 

Hello all and thanks for looking!  I am trying to copy my ACTIVE Sheet (named "Lists", but I would prefer it remains dynamic as "active" sheet) to all open workbooks (move to end also).  The issue is I am getting this error, and I am not quite understanding it.

Option Explicit

Sub CopyToAllOpen()

Dim wb As Workbook
Dim sh As Worksheet

Set sh = ActiveSheet

For Each wb In Application.Workbooks
If Not sh.Parent Is wb Then
sh.Copy After:=wb.Sheets(wb.Sheets.Count)
End If
Next wb

End Sub

2023-12-08_15-34-01.png2023-12-08_13-21-12.png

 
Posted : 09/12/2023 4:41 pm
(@keebellah)
Posts: 373
Reputable Member
 

you have to se a variable that retains the file from where you're copying it since this is the 'source workbook' 

 
Posted : 10/12/2023 2:56 am
(@debaser)
Posts: 836
Member Moderator
 

You probably have a hidden workbook. Test for that before trying to copy:

 

Sub CopyToAllOpen()

Dim wb As Workbook
Dim sh As Worksheet

Set sh = ActiveSheet

For Each wb In Application.Workbooks
If wb.Windows(1).Visible Then
If Not sh.Parent Is wb Then
sh.Copy After:=wb.Sheets(wb.Sheets.Count)
End If
End If
Next wb

End Sub

 
Posted : 12/12/2023 9:16 am
(@webbers)
Posts: 147
Estimable Member
Topic starter
 

@Velouria,

Perfect!  The macro was residing in my Personal Workbook (which is hidden), and I carefully review the differences in the original code and your revised code.  I now understand the WHY, and I thank you for that.  This code is a HUGE timesaver.  Thanks again so very much for your help, it is greatly appreciated!

 
Posted : 12/12/2023 2:56 pm
Share: