Save a File with a Password Q

  • Thread starter Thread starter Seanie
  • Start date Start date
S

Seanie

Is it possible to save via Code a file with a password that resides is
a cell within the workbook?
 
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
 
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
 
Back
Top