Run-time error '1004': Shared Workbook and Macro

ndeboni1

New Member
Joined
Aug 16, 2012
Messages
2
Hello All,

I am having an issue with a macro abd sharing a workbook. The macro enables me to using grouping while protecting the worksheet. Here is the code:
Private Sub Workbook_Open()
Dim wksht As Worksheet
For Each wksht In ThisWorkbook.Sheets
With wksht
.EnableOutlining = True
.Protect contents:=True, userInterfaceOnly:=True
End With
Next wksht
End Sub

I recieve this message when I save the shared workbook and reopen it.

Run-time error '1004':
Method 'Proctec' of object '_Worksheet' failed.

Any suggestions to use the shared protected worksheets with the grouping would be great. Thank you.

If this helps here is the link to download the document. https://docs.google.com/open?id=0B5VfEg2PhuTIaHpoVzNLa1VxZXM
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Got it. For future reference.
Option Explicit

Private Sub Workbook_Open()

' check shared and stop sharing
With ActiveWorkbook
If .MultiUserEditing Then
Application.DisplayAlerts = False
.ExclusiveAccess
Application.DisplayAlerts = True
End If
End With

'enable outlining on sheet1
With Sheet1
.EnableOutlining = True
.Unprotect "password"
.Protect Password:="password", UserInterfaceOnly:=True
End With

'resave with sharing switched on
With ActiveWorkbook
Application.DisplayAlerts = False
.SaveAs Filename:=.FullName, AccessMode:=xlShared
Application.DisplayAlerts = True
End With

End Sub

check the sheet number in the code to make sure it aligns with the one you are trying to group. (sheet#).
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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