PC Review


Reply
Thread Tools Rate Thread

.bat file to enter password protected .xls sheet

 
 
Paul Lambson
Guest
Posts: n/a
 
      14th Nov 2008
I am trying to create a .bat file to open a .xls file. But the file is
password protected to modify. I can't figure out the code to enter the
password in the .bat file and then hit the "OK" key

start "C:\Program Files\Microsoft Office\OFFICE11\EXCEL.EXE"
"W:\YIELDMGT\Paul Lambson\SAS\ThanksChart.xls"
nircmd.exe dlg "password" click OK

the first two lines get me to the prompt for the password but i'm
stuck there

HELP~~

Paul
 
Reply With Quote
 
 
 
 
Joel
Guest
Posts: n/a
 
      14th Nov 2008
I went to microsoft website and there doesn't appearr to be a password switch

see

http://office.microsoft.com/en-us/ex...0301033.aspx#4

Another solution would be to open another workbook with no password. In
this workbook put a Workbook_Open event. The workbook Open Event can open a
2nd workbook with a password.

"Paul Lambson" wrote:

> I am trying to create a .bat file to open a .xls file. But the file is
> password protected to modify. I can't figure out the code to enter the
> password in the .bat file and then hit the "OK" key
>
> start "C:\Program Files\Microsoft Office\OFFICE11\EXCEL.EXE"
> "W:\YIELDMGT\Paul Lambson\SAS\ThanksChart.xls"
> nircmd.exe dlg "password" click OK
>
> the first two lines get me to the prompt for the password but i'm
> stuck there
>
> HELP~~
>
> Paul
>

 
Reply With Quote
 
Peter T
Guest
Posts: n/a
 
      14th Nov 2008
I like Joel's idea to use a dummy file's open event to open the p/w
protected file.

Could also try a vbs script if your system allows it

''' start vbs script
On Error Resume Next
Set oxl = GetObject(, "excel.application")
If oxl Is Nothing Then
Set oxl = CreateObject("excel.application")
End If

If oxl Is Nothing Then
MsgBox "Cannot start Excel"
Else
oxl.Visible = True
Set owb = oxl.Workbooks.Open("C:\path\file.xls", , , ,"password") ' <<
change path & password
If owb Is Nothing Then
MsgBox "Cannot open file"
Else
owb.Visible = True
oxl.Windows(1).WindowState = -4137 'xlMaximized
End If

End If
''' end vbs script

copy the above into a text editor (eg Notepad) and save with a *.vbs
extention, say onto the desktop.


Regards,
Peter T



"Paul Lambson" <(E-Mail Removed)> wrote in message
news:bf49a6aa-a66a-45cb-9fe5-(E-Mail Removed)...
>I am trying to create a .bat file to open a .xls file. But the file is
> password protected to modify. I can't figure out the code to enter the
> password in the .bat file and then hit the "OK" key
>
> start "C:\Program Files\Microsoft Office\OFFICE11\EXCEL.EXE"
> "W:\YIELDMGT\Paul Lambson\SAS\ThanksChart.xls"
> nircmd.exe dlg "password" click OK
>
> the first two lines get me to the prompt for the password but i'm
> stuck there
>
> HELP~~
>
> Paul



 
Reply With Quote
 
Paul Lambson
Guest
Posts: n/a
 
      14th Nov 2008
Peter it tried your VBS script. It lauches excel and tries to launch
the .xls but doensn't do the password. any tips?

this is the code
''' start vbs script
On Error Resume Next
Set oxl = GetObject(, "excel.application")
If oxl Is Nothing Then
Set oxl = CreateObject("excel.application")
End If


If oxl Is Nothing Then
MsgBox "Cannot start Excel"
Else
oxl.Visible = True
Set owb = oxl.Workbooks.Open("W:\YIELDMGT\Paul Lambson\SAS
\ThanksChart.xls", , , ,"XXXXX") ' <<
change path & password
If owb Is Nothing Then
MsgBox "dang it paul do this right"
Else
owb.Visible = True
oxl.Windows(1).WindowState = -4137 'xlMaximized
End If


End If
''' end vbs script
 
Reply With Quote
 
Peter T
Guest
Posts: n/a
 
      14th Nov 2008
It worked for me but try the exact same code in VBA,
Sub abc()
' the vbs code here
' comment the On Error line
End Sub

get rid of this line (my mistake though not the current problem)
> owb.Visible = True


Actually not sure the WindowState line below it helps, try w/out

Once you've got it working amend the vbs
(don't declare any variables or use any named xl constants)

Regards,
Peter T



"Paul Lambson" <(E-Mail Removed)> wrote in message
news:4ae8fb87-1cd9-4a25-adf2-(E-Mail Removed)...
> Peter it tried your VBS script. It lauches excel and tries to launch
> the .xls but doensn't do the password. any tips?
>
> this is the code
> ''' start vbs script
> On Error Resume Next
> Set oxl = GetObject(, "excel.application")
> If oxl Is Nothing Then
> Set oxl = CreateObject("excel.application")
> End If
>
>
> If oxl Is Nothing Then
> MsgBox "Cannot start Excel"
> Else
> oxl.Visible = True
> Set owb = oxl.Workbooks.Open("W:\YIELDMGT\Paul Lambson\SAS
> \ThanksChart.xls", , , ,"XXXXX") ' <<
> change path & password
> If owb Is Nothing Then
> MsgBox "dang it paul do this right"
> Else
> owb.Visible = True
> oxl.Windows(1).WindowState = -4137 'xlMaximized
> End If
>
>
> End If
> ''' end vbs script



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Protected sheet, On Enter moves next. Can I stop this? misseill Microsoft Excel Worksheet Functions 3 27th Oct 2007 03:29 PM
Re: Using TAB vs ENTER for data entry in a protected sheet Gord Dibben Microsoft Excel Worksheet Functions 1 12th Jan 2007 10:35 PM
Help! Password Protected Form to mask the enter password w/ aster =?Utf-8?B?TUw=?= Microsoft Access 3 14th Jul 2005 11:10 PM
excel - macro code to open a protected sheet, enter passowrd, and then protect sheet arunjoshi Microsoft Excel Programming 1 2nd May 2004 03:50 PM
VBa, Password protected sheet fails to get unprotected with the same password Hans Rattink Microsoft Excel Programming 3 28th Jul 2003 02:30 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:26 AM.