FileDialog(msofiledialogsaveas) Allow User to Enter Password to Modify

antman2988

Board Regular
Joined
Jun 28, 2018
Messages
78
Hello,

I've been researching for a while now on how to allow the user to select General Option from the Tools drop-down menu during the FileDialog window. This is the current code I have, but is it even possible to enable this option?

VBA Code:
With oFD2
        'strUser = Environ("USERNAME")
        .ButtonName = "Save"
        .initialFileName = "[Excluded]" _
            & saveDate & " PE's LD.xlsb"
        .FilterIndex = 3
        .Title = "Please choose the folder for the appropriate fiscal year and period."
        If .Show = 0 Then Exit Sub 'user cancelled
        .Execute  'save active workbook
        'path2 = .SelectedItems(1)
        'Call ReadOnly(path2)
        '.ChangeFileAccess Mode:=xlReadWrite, WritePassword:="TCBPU"
End With

Basically, I need to allow the user to enter a password in the Password to Modify field. Is there another way to do this if I already have a predetermined password? I tried changing the file access, but it didn't work correctly.

Thanks!
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
If you use VBA to automate things, it implicitly means that you want to have full control. I would therefore recommend making an optional password entry available by means of an input box.
You could use one of Excel's native dialogs, including the General Option, but then you relinquish control. This way there is no possibility to capture user input. You can catch whether the file was actually saved but you remain unaware in which folder and with which file name this has happened or which password was used (in case of unexpected but necessary recovery).

VBA Code:
Sub antman2988()
    
    Dim d As Dialog, i As Long, r As Variant
    
    For i = 1 To 3
        Set d = Application.Dialogs(xlDialogSaveAs)
        ' try Tools > General Options > enter your password
        r = d.Show
    Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,213,543
Messages
6,114,243
Members
448,555
Latest member
RobertJones1986

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