Excel Workbook Desktop Shortcut with Auto password?

7,462

There is no direct way, but with a little coding, you can get Excel to process command line parameters and open it from a launcher spreadsheet.

Using a shortcut that looks like this:

"C:\Program Files\Microsoft Office\Office12\EXCEL.EXE" /e/myfilename/mypassword "C:\MyExcelFiles\test.xlsb"

You can use the following code to get the command line - you will then have to extract the parameters you passed with /e, as the whole line gets returned

Declare Function StrLenA Lib "kernel32.dll" Alias "lstrlenA" (ByVal Ptr As Long) As Long
Declare Function GetCommandLineA Lib "kernel32.dll" () As Long
Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (ByRef pDst As Any, pSrc As Any, ByVal ByteLen As Long)

Function GetCommandLine() As String

Dim CmdStr As Long
Dim N As Long
Dim Buffer As String

   CmdStr = GetCommandLineA 'Get a pointer to a string, which contains the command line
   N = StrLenA(CmdStr) 'Get the length of that string
   Buffer = String(N, Chr$(0)) 'Create a buffer
   CopyMemory ByVal Buffer, ByVal CmdStr, N 'Copy to the buffer
   GetCommandLine = Buffer

End Function
Share:
7,462

Related videos on Youtube

owenmelbz
Author by

owenmelbz

Updated on September 18, 2022

Comments

  • owenmelbz
    owenmelbz over 1 year

    I've got a bunch of password-protected Excel workbooks on my secured LAN (no wan) computer.

    Is it possible to parse the password into a shortcut so it would automatically open a workbook as long as the password is correct?

    For example:

    "S:\resources\Audit.xls" -password "mypass"
    
    • CharlieRB
      CharlieRB almost 12 years
      Can you please clarify; is the file password protected on open or just the sheets within the workbook are protected? There is a big difference between the two.
  • datatoo
    datatoo almost 12 years
    seems like an answer
  • ChrisZ
    ChrisZ over 4 years
    I am new to this but I need this solution.. How can I execute this?