Not able to hide Excel worksheet (2nd Time) through VBA

nuage

New Member
Joined
Aug 29, 2018
Messages
5
HI,
Not able to hide Worksheets (2nd Time) in following code. Although with first occurrence i.e. Sourcewb worksheets get hide. But with SourcewbA code all the worksheet remains unhide. I tried to even close first and then open second file.


Dim Sourcewb As Worksheet
Dim SourcewbA As Worksheet


Workbooks.Open Filename:= "NTRv1" & ".xlsm"


' Hiding Worksheet of First Workbook
For Each Sourcewb In ThisWorkbook.Worksheets
If Sourcewb.Name <> ThisWorkbook.ActiveSheet.Name Then
Sourcewb.Visible = False
End If
Next Sourcewb


Workbooks("NTRv1" & ".xlsm").Save
Workbooks("NTRv1" & ".xlsm").Close
Workbooks.Open Filename:= "NTRv2" & ".xlsm"
Workbooks("NTRv2").Activate



' Hiding Worksheet of Second Workbook
For Each SourcewbA In ThisWorkbook.Worksheets
If SourcewbA.Name <> ThisWorkbook.ActiveSheet.Name Then
SourcewbA.Visible = False
End If
Next SourcewbA
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
wrong workbook?

Code:
For Each SourcewbA In [COLOR=#ff0000]ActiveWorkbook[/COLOR].Worksheets
If SourcewbA.Name <> [COLOR=#ff0000]ActiveWorkbook[/COLOR].ActiveSheet.Name Then

or perhaps
Code:
For Each SourcewbA In [COLOR=#ff0000]ActiveWorkbook[/COLOR].Worksheets
If SourcewbA.Name <> ThisWorkbook.ActiveSheet.Name Then

depends which one is correct for your situation
 
Last edited:
Upvote 0
wrong workbook?

Code:
For Each SourcewbA In [COLOR=#ff0000]ActiveWorkbook[/COLOR].Worksheets
If SourcewbA.Name <> [COLOR=#ff0000]ActiveWorkbook[/COLOR].ActiveSheet.Name Then

or perhaps
Code:
For Each SourcewbA In [COLOR=#ff0000]ActiveWorkbook[/COLOR].Worksheets
If SourcewbA.Name <> ThisWorkbook.ActiveSheet.Name Then

depends which one is correct for your situation


Thanks a lot. First code deliver the desired result.
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,198
Members
453,022
Latest member
RobertV1609

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