Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

Make a file Paasword Protected

0

My file is opened (only 1 file is opened)

i need a vba code i will run the code and the file become paasword protected

Without putting the paasword the file cant be opened and without paasword it cant be modified

So plz have a look sir

Answer
Discuss

Answers

0
Selected Answer
ActiveWorkbook.SaveAs ActiveWorkbook.Fullname, ActiveWorkbook.FileFormat, "yourpassword"

Change ActiveWorkbook to suit. If file is not saved already, add the fileformat type to replace ActiveWorkbook.FileFormat. Record a macro and save a file to a type if you don't know what the fileformat is for a file type.

Discuss

Discussion

Sir there is No sub and end sub
how i will run the macro?
Plz guide Sir
style36 (rep: 24) Aug 29, '19 at 11:14 am
The usual method would be to add a Sub to a Module. Name it what you want.

Or, record a macro. Then edit it. Record from the Developer ribbon. If not enabled, right click the ribbon and customize it to enable it. There are many tutorials that show how to add a Module and Sub routines. e.g.

https://www.teachexcel.com/excel-tutorial/2018/use-macros-with-userforms
KenHobson (rep: 55) Aug 29, '19 at 11:48 am
let us suppose file name is 12.xlsb and paasword is 1234
then what would be the code
style36 (rep: 24) Aug 29, '19 at 11:59 am
and Change ActiveWorkbook to suit. If file is not saved already
My file is opened then activeworkbook to suit and if file is not saved already 
Plz explain Sir bcoz i searched on the google about this problem I got the code 
but that code works in 1 file but in 2nd file it was not worked so plz explain about the code which u sented 
and plz provide the code as per my exanple so i can understand
style36 (rep: 24) Aug 29, '19 at 12:05 pm
Thnx Sir for giving ur precious time and Great Support to this post
Have a Great Day Sir
style36 (rep: 24) Aug 29, '19 at 1:09 pm
Add to Discussion


Answer the Question

You must create an account to use the forum. Create an Account or Login