Macro help, after pasting with Call option...... stopped working and gives error

K0st4din

Well-known Member
Joined
Feb 8, 2012
Messages
501
Office Version
  1. 2016
  2. 2013
  3. 2011
  4. 2010
  5. 2007
Platform
  1. Windows
Hi, so far I have used this macro so that when I close the workbook, it can hide the worksheets and leave only Sheet1. This macro is located in ThisWorkbook .
However, since I need to add one more macro, I'm trying to make the two macros fire one after the other in the Module. Ie Call 1st macro and then Call 2nd macro.
The one in ThisWorkbook - I stopped it.
I made a new name with a new Module of the same macro but already as a Sub with new name ().
When I press the button the 1st macro works and the second one gives me an error that in this case I can't use Me.Sheets
I'm asking for some help, why it doesn't want to work and where I'm doing wrong.
Thank you in advance.
VBA Code:
'This one is in ThisWorkbook
Private Sub Workbook_BeforeClose(Cancel As Boolean)
    Dim oneSheet As Worksheet

    Sheet1.Visible = xlSheetVisible

     For Each oneSheet In Me.Sheets
         If oneSheet.Name <> Sheet1.Name Then
             oneSheet.Visible = xlSheetVeryHidden
         End If
     Next oneSheet

End Sub
VBA Code:
'This one is in new SUB in Module
Sub skrivane_na_sheetove()
    Dim oneSheet As Worksheet

    Sheet1.Visible = xlSheetVisible

     For Each oneSheet In Me.Sheets
         If oneSheet.Name <> Sheet1.Name Then
             oneSheet.Visible = xlSheetVeryHidden
         End If
     Next oneSheet
     
End Sub
VBA Code:
Sub zapazvanefileiskrivanesheetove()
Call btnSaveTheWorkbook_Click 'this one work
Call skrivane_na_sheetove 'This one NO
End Sub
2023-12-08_073408.jpg
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Replace Me with ThisWorkbook.
 
Upvote 1
Solution
Thank you very much for your prompt assistance.
Now everything works as it should.
I wish you health and many happy moments.
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,159
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top