Protecting VBA (Excel) code
Guessing, the problem has nothing to do with the project being locked but
more likely a file named DSNDirectory & DSNFilename (btw note & vs +)
already exisits. For testing, comment the line that disables alerts.
If that's the reason it'll be up you if you want to check if a such a file
already exists or maybe
on error resume next
Kill theFile
On error goto 0
or better still include an error handler
On error goto errH
'code
exit sub
errH:
msgbox err.number & vbcr & err.description
exit sub
Regards,
Peter T
"Malc" wrote in message
...
I have a model that uses VBA to save the file. The variables are
dimmed as appropriate and then I use this code to compile the save
filename:
DSNDirectory = "\\" & Range("appserver") & "\" & Range("appprogdir") &
"\utils\"
DSNFilename = Range("dsnfile")
Then I use
Application.DisplayAlerts = False
ChDir DSNDirectory
ActiveWorkbook.SaveAs FileName:=DSNDirectory + DSNFilename, _
FileFormat:=xlTextMSDOS, CreateBackup:=False
DisplayAlerts = True
and this saves the particular worksheet as a text file.
And this all works until I lock the project for viewing and protect it
with a password. Once that's done running the macro that contains the
code described above results in an error 1004 method 'SaveAs' of
object '_workbook' failed. I can't debug it because it's locked, and
if I unlock it the code works. So I can't work out what's wrong!
Does anyone have any ideas?
Thanks in advance
|