Unlock project for viewing within a macro

P

P McConnell

I'd like to protect the macros in a workbook but allow the user to save it as
a different filename. Once I lock the VBAProject I can't save as another
name. I'm thinking a solution would be to wrap unprotect and re-protect
around the save (if that's possible), but I'm stumped on the code. Please
see below...

'I need code to unprotect project here
ConNum = TextBox1.Value
ActiveWorkbook.SaveAs Filename:="C:\Orders\" & ConNum & ".xls"
Application.RecentFiles.Add Name:=ThisWorkbook.FullName
'Also code to protect project here

Thanks!
 
D

Dave Peterson

You should be able to save the workbook with the project locked or unlocked.

What happened when you tried it?
 
P

P McConnell

When protected and trying to rename, from File>Save As I get two messages.
"You cannot save to this file format when the VBA project is protected."
followed by "Document not saved". From the button on the userform where the
code is I get a 1004 with "You cannot save to this file format when the VBA
project is protected." I tried including the file format in the code (below)
and got the same results. BTW I'm in Excel 2003.

ActiveWorkbook.SaveAs Filename:="C:\Orders\" & ConNum & ".xls", FileFormat:=
xlNormal, AddToMru:=True

Thanks Again
 
P

P McConnell

It appears that my reply was not added to the thread. This is my first
attempt at using the discussion group, please forgive the duplication.

....When protected and trying to rename, from File>Save As I get two messages.
"You cannot save to this file format when the VBA project is protected."
followed by "Document not saved". From the button on the userform where the
code is I get a 1004 with "You cannot save to this file format when the VBA
project is protected." I tried including the file format in the code (below)
and got the same results. BTW I'm in Excel 2003.

ActiveWorkbook.SaveAs Filename:="C:\Orders\" & ConNum & ".xls", FileFormat:=
xlNormal, AddToMru:=True

Thanks Again
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top