ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Save a File with a Password Q (https://www.excelbanter.com/excel-programming/425551-save-file-password-q.html)

Seanie

Save a File with a Password Q
 
Is it possible to save via Code a file with a password that resides is
a cell within the workbook?


Mike H

Save a File with a Password Q
 
Hi,

Maybe something along these lines

Sub Save_Me()
MyPass = Sheets("Sheet1").Range("A1").Value
Fname = ActiveWorkbook.Name
ActiveWorkbook.SaveAs Filename:=Fname, Password:=MyPass
End Sub


Mike

"Seanie" wrote:

Is it possible to save via Code a file with a password that resides is
a cell within the workbook?



John

Save a File with a Password Q
 
this example may be a little more than you were looking for as includes a
test on Path to detrmine if file has been previousley saved - it also shows
how to include password from a range value.

Hope useful

Sub SaveBook()
Dim Passwrd As Range
Dim FName As Variant
Dim FPath As String

'change sheet name & range as required
Set Passwrd = Worksheets("Sheet1").Range("A1")

Application.DisplayAlerts = False

With ThisWorkbook

FName = .Name
FPath = .Path

If FPath < "" Then

.SaveAs Filename:=FName, Password:=Passwrd.Value

Else

FName = Application.GetSaveAsFilename( _
fileFilter:="Excel Files (*.xls), *.xls")

If FName < False Then

.SaveAs Filename:=FName, Password:=Passwrd.Value

End If

End If

End With

Application.DisplayAlerts = True

End Sub


--
jb


"Seanie" wrote:

Is it possible to save via Code a file with a password that resides is
a cell within the workbook?




All times are GMT +1. The time now is 11:27 PM.

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