ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   unlock and lock VBAProject (https://www.excelbanter.com/excel-programming/315873-unlock-lock-vbaproject.html)

Lenny_821[_3_]

unlock and lock VBAProject
 

Because when I try to save the document it give's me the followin
message;
"you cannot save to this fileformat when the VBA project is protected"

here's the code;

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, _
Cancel As Boolean)

Dim MyVar

On Error GoTo EndHere

Application.ScreenUpdating = False
ActiveWorkbook.Unprotect

'my code here

Application.ScreenUpdating = True
ActiveWorkbook.Protect

Exit Sub

EndHe
MyVar = MsgBox(Text1, 16, Text2)

End Su

--
Lenny_82
-----------------------------------------------------------------------
Lenny_821's Profile: http://www.excelforum.com/member.php...fo&userid=1517
View this thread: http://www.excelforum.com/showthread.php?threadid=27556


Dave Peterson[_4_]

unlock and lock VBAProject
 
I've seen that message when I saved a workbook with a protected project in the
xl95 file format. (I didn't try other fileformats.)

But do you really need to use whatever file format you're using?

And what file format are you using?



Lenny_821 wrote:

Because when I try to save the document it give's me the following
message;
"you cannot save to this fileformat when the VBA project is protected"

here's the code;

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, _
Cancel As Boolean)

Dim MyVar

On Error GoTo EndHere

Application.ScreenUpdating = False
ActiveWorkbook.Unprotect

'my code here

Application.ScreenUpdating = True
ActiveWorkbook.Protect

Exit Sub

EndHe
MyVar = MsgBox(Text1, 16, Text2)

End Sub

--
Lenny_821
------------------------------------------------------------------------
Lenny_821's Profile: http://www.excelforum.com/member.php...o&userid=15179
View this thread: http://www.excelforum.com/showthread...hreadid=275560


--

Dave Peterson



All times are GMT +1. The time now is 04:44 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com