protect and unprotect workbook using vba code

jackni

Board Regular
Joined
Feb 10, 2011
Messages
73
i'm looking for a vba code to solve the following problem
a .xlsm workbook, the protect workbook passwork is known as "111111", the VBA project password is "222222", and how to write vba code to insert a new sheet, suppose the workbook has three worksheet, now using vba code to unprotect workbook, and auto insert a newsheet, then protect workbook again, whcih the password remains as "111111"
using a commondbutton to do this, everytime you click, insert a new sheet.

hope someone can help, many thanks!
 
michael,

thanks for all your replied posts.
i have upload the excel files and two pictures to the mediafire, the website is http://www.mediafire.com/?0zufu0k3b13qgej
i'm now come up against two problems,
the first is the button in excel files cann't working because the excel disabled macros, and the second is developer ribbon ->macro security-> enable macro buttion missing
i don't konw why, could you fix this for me?

thank you again!
 
Upvote 0

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Did you save the file as Macro enabled, which you can do in V7 or higher?
If you don't do this then the workbook, won't be saved with macros included.
I cannot view external files from my current site, I have restictions imposed on my computer.
 
Upvote 0
i saved my file as .xlsm
usually my macro works fine, but this time it cann't working, i don't know why...
 
Upvote 0

Forum statistics

Threads
1,226,227
Messages
6,189,748
Members
453,567
Latest member
kentbarbie

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