Protected access to excel files - how to

mr2bart

Board Regular
Joined
Dec 18, 2014
Messages
57
Dear all,

I am using now protected access to my excel file due to many confidential information inside. It's working very well.
But I have an issue. On the file which is restricted to some users, I do some exports of data. My file is creating another workbook and sheets with some reports copied from my original file.
My problem is that these export files are free access to everybody, I would like to transfer on them the same restricted access list as the original file.
Any way to do that ?

thanks!
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
When your code creates the other workbooks, call this code to save it:

Code:
Sub SaveWithPassword()

    Dim sFileNameExt As String
    Dim sFolder As String
    Dim sReadOnlyPwd As String
    Dim sWritePwd As String
    
    With Application.FileDialog(msoFileDialogFolderPicker)
        .InitialFileName = ThisWorkbook.Path
        .Title = "Select the Save folder"
        If .Show = -1 Then
            sFolder = .SelectedItems(1)
            If Right(sFolder, 1) <> "\" Then
                sFolder = sFolder & "\"
            End If
        Else
            sFolder = vbNullString
        End If
    End With
    If sFolder = vbNullString Then
        MsgBox "No folder was specified.  File not saved", , "File Not Saved"
        GoTo End_Sub
    End If

    sFileNameExt = InputBox("Enter the FileName.Ext for the file", "Enter FileName.Ext", "name.ext")
    sReadOnlyPwd = InputBox("Enter the read-only password for the file.  ", "Enter Read-Only Password", "readonly")
    sWritePwd = InputBox("Enter the editing password for the file.  .", "Enter Editing Password", "editing")
    
    On Error Resume Next
    ActiveWorkbook.SaveAs Filename:=sFolder & sFileNameExt, _
        FileFormat:=xlExcel12, CreateBackup:=False, Password:=sReadOnlyPwd, WriteResPassword:=sWritePwd
    If Err.Number <> 0 Then
        MsgBox "File Not Saved.  Invalid parameter specified in one or more of:" & vbLf & _
            "FileName.Ext: " & sFileNameExt & vbLf & _
            "File Path: " & sFolder & vbLf & _
            "Read-Only Password: " & sReadOnlyPwd & vbLf & _
            "Write Password: " & sWritePwd & vbLf & vbLf & _
            "Check for errors and rerun save function.", vbOKOnly + vbCritical, "File Not Saved"
    End If

End_Sub:
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,207
Members
448,554
Latest member
Gleisner2

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