• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

save as password protected workbook

ysherriff

Member
hello all.

I am going to be modifying my process and codes later but in the meantime i need help with this quirk.

i am generating individual workbooks based on UID and placing them in a seperate directory. While the workbook is being saved, I want to password protect the workbook based on EMPLID which is included in the list. I saw this vba code on the internet while searching.

Code:
ActiveWorkbook.SaveAs filename:="C:\SAP Imports\Sales Orders\"& Range("A1")&".xlsm", FileFormat:= _ xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False _ , CreateBackup:=False

On my code, i have the EMPLID as string already named. This is how the workbook is being currently saved in my code:

ActiveWorkbook.SaveAs pathStr & "\Reports\" & reportName

I have the EMPLID already defined as a string, would i modify my save as code as

ActiveWorkbook.SaveAs pathStr & "\Reports\" & reportName , FileFormat:= _ xlNormal, Password:=EMPLID, WriteResPassword:=EMPLID, ReadOnlyRecommended:=False _ , CreateBackup:=False"

I am going to test it out to see if it works but let me know if i am on the right track. attached is the workbook with code
 

Attachments

  • Monthly PSR Calculator Generator v1.0.xls
    113 KB · Views: 7
Last edited by a moderator:
Yes your heading in the right direction

In your code I don't see a variable EMPLID only a psrEMPLID variable?

You also may need to leave the WriteResPassword:=""
depending on your requirements

Password:=EMPLID 'Requires a Password to open the file
WriteResPassword:=EMPLID 'Requires a Password to save or resave (rename) the file
 
Back
Top