hondaman2003
Programmer
I know how to open an excel document and change data and formatting. How can I save the file with a password so it can not be openned at all without the password? Separately how can I save with a password so it can only be openned read only without the password?
Here is my code to open and save the file
Dim appExcel As Excel.Application
Dim myWorkbook As Excel.Workbook
Dim mySheet As Excel.Worksheet
Set appExcel = CreateObject("Excel.Application")
Set myWorkbook = appExcel.Workbooks.Open("R:\Specialty\Factor\Assay reports\FACTOR OVERVIEW " & Format([End date], "mmm yyyy") & ".xls")
Set mySheet = myWorkbook.Sheets("Prescribed_Dispensed_Difference")
<commands to edit data and change formatting>
mySheet.Columns("A:I").EntireColumn.AutoFit
mySheet.Columns("I").NumberFormat = "0.00%"
myWorkbook.Save
myWorkbook.Close
Set appExcel = Nothing
Set myWorkbook = Nothing
Set mySheet = Nothing
Here is my code to open and save the file
Dim appExcel As Excel.Application
Dim myWorkbook As Excel.Workbook
Dim mySheet As Excel.Worksheet
Set appExcel = CreateObject("Excel.Application")
Set myWorkbook = appExcel.Workbooks.Open("R:\Specialty\Factor\Assay reports\FACTOR OVERVIEW " & Format([End date], "mmm yyyy") & ".xls")
Set mySheet = myWorkbook.Sheets("Prescribed_Dispensed_Difference")
<commands to edit data and change formatting>
mySheet.Columns("A:I").EntireColumn.AutoFit
mySheet.Columns("I").NumberFormat = "0.00%"
myWorkbook.Save
myWorkbook.Close
Set appExcel = Nothing
Set myWorkbook = Nothing
Set mySheet = Nothing