ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   changing a file password from something to nothing (https://www.excelbanter.com/excel-programming/382644-changing-file-password-something-nothing.html)

Mike Gallagher[_2_]

changing a file password from something to nothing
 
I would like to save a file with a password and then later save the same file
in the same location and with the same name but remove the password. Does any
one know what the syntax should be. I'm new to VBA, but Excel seems to be
acting weird when I try to do this. Does anyone know why I can't just use
the SaveAs method and specify Password:="". The only way the code does work
is if I first changed the password to a string and then change it again to
nothing. It seems redundant. Maybe I've missed something.

This is the routine that finally worked:

Sub save_wo_passwd()
Application.DisplayAlerts = False
Fname = ActiveWorkbook.FullNameURLEncoded
ActiveWorkbook.SaveAs Filename:=Fname, _
FileFormat:=xlNormal, Password:="1234"
ActiveWorkbook.SaveAs Filename:=Fname, Password:=""
Application.DisplayAlerts = True
ActiveWorkbook.Save
ActiveWorkbook.Close
End Sub

Corey

changing a file password from something to nothing
 
I can't see how you can have 2 workbooks with the same name in the same folder??

"Mike Gallagher" wrote in message
...
I would like to save a file with a password and then later save the same file
in the same location and with the same name but remove the password. Does any
one know what the syntax should be. I'm new to VBA, but Excel seems to be
acting weird when I try to do this. Does anyone know why I can't just use
the SaveAs method and specify Password:="". The only way the code does work
is if I first changed the password to a string and then change it again to
nothing. It seems redundant. Maybe I've missed something.

This is the routine that finally worked:

Sub save_wo_passwd()
Application.DisplayAlerts = False
Fname = ActiveWorkbook.FullNameURLEncoded
ActiveWorkbook.SaveAs Filename:=Fname, _
FileFormat:=xlNormal, Password:="1234"
ActiveWorkbook.SaveAs Filename:=Fname, Password:=""
Application.DisplayAlerts = True
ActiveWorkbook.Save
ActiveWorkbook.Close
End Sub



Mike Gallagher[_2_]

changing a file password from something to nothing
 
Corey,
Sorry, I may have made it sound that way, but I only want to end up with
one version of the file. I just want to change it so that it is not password
protected. I'm actually doing this on a network with many similar files in
different locations. I want to get these files to their destinations, run a
series of routines on them, and then allow them to be opened by recipients.

"Corey" wrote:

I can't see how you can have 2 workbooks with the same name in the same folder??



Tom Ogilvy

changing a file password from something to nothing
 
Open it, providing the password, then do a SaveAs using the same name with
no password.

--
Regards,
Tom Ogilvy

"Mike Gallagher" wrote in message
...
Corey,
Sorry, I may have made it sound that way, but I only want to end up with
one version of the file. I just want to change it so that it is not
password
protected. I'm actually doing this on a network with many similar files in
different locations. I want to get these files to their destinations, run
a
series of routines on them, and then allow them to be opened by
recipients.

"Corey" wrote:

I can't see how you can have 2 workbooks with the same name in the same
folder??






All times are GMT +1. The time now is 07:23 PM.

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