locked
Script code to set password excel RRS feed

  • Question

  • Dear all, I have a Little troubble with a script on VBS, I wish set a password to Excel files (also PDF DOC and PPT files), I have a code with VBS and I  execute the script and the password protection its ok, but after execute the script the contents of the excel file dissapears, (maybe is creating a new file)

    Set objExcel = CreateObject("Excel.Application")
    objExcel.Visible = True
    objExcel.DisplayAlerts = FALSE
    
    Set objWorkbook = objExcel.Workbooks.Add
    Set objWorksheet = objWorkbook.Worksheets(1)
    
    objWorksheet.Cells(1, 1).Value = Now
    objWorkbook.SaveAs "EXCELFILE",,"PASSWORD"
    objExcel.Quit
    

    Whyit can be erasing the file information?

    What needed to preserve the contents of the file?, Does it serve me the same code to pdf and doc files?, MANY THANKS!!

    Monday, November 30, 2015 4:00 PM

Answers

All replies

  • I'd probably ask them here about the excel object model.

    https://social.msdn.microsoft.com/Forums/office/en-US/home?forum=exceldev

     

     

     


    Regards, Dave Patrick ....
    Microsoft Certified Professional
    Microsoft MVP [Windows]

    Disclaimer: This posting is provided "AS IS" with no warranties or guarantees , and confers no rights.

    • Proposed as answer by Just Karl Monday, November 30, 2015 4:18 PM
    • Marked as answer by Just Karl Tuesday, December 8, 2015 5:22 PM
    Monday, November 30, 2015 4:03 PM
  • Thanks Dave
    Monday, November 30, 2015 4:04 PM
  • You're welcome.

     

     


    Regards, Dave Patrick ....
    Microsoft Certified Professional
    Microsoft MVP [Windows]

    Disclaimer: This posting is provided "AS IS" with no warranties or guarantees , and confers no rights.

    Monday, November 30, 2015 4:05 PM