VBA open workbook xlxs in 2003 that contains a password

  • Thread starter Thread starter macmeldrum
  • Start date Start date
M

macmeldrum

Hi,

I have a folder a 5 files (one of them has a password to open it).
They are all xlxs and I am working on 2003 with the file convertor
installed.

I have the following vba workbooks.open(file, false, true,
"IncorrectPassword")

What I would like to do is if I come to the file with the password not
open it and just move on.

Instead I keep getting the password open display and I don't want to
have to click out of it.

Any help much appreciated.

Mac
 
dim wkbk as workbook
....

set wkbk = nothing
on error resume next
set wkbk = workbooks.open(filename:=file, ..., password:="IncorrectPassword")
on error goto 0

if wkbk is nothing then
'workbook didn't open
else
'do the real work
end if

===
Personally, I find using the keyword parms makes the code much easier to
understand.
 
dim wkbk as workbook
...

set wkbk = nothing
on error resume next
set wkbk = workbooks.open(filename:=file, ..., password:="IncorrectPassword")
on error goto 0

if wkbk is nothing then
  'workbook didn't open
else
  'do the real work
end if

===
Personally, I find using the keyword parms makes the code much easier to
understand.













--

Dave Peterson- Hide quoted text -

- Show quoted text -

Hi Dave,

Thanks for your quick response. The problem I'm getting is that
because I'm in 2003 and the file is xlxs then the password prompt is
coming up and I can 't move on without pressing return.

Cheers

Mac
 
Even with the "on error" stuff?

If that's true, then I don't have a suggestion. (I don't use the compatibility
pack.)

Sorry.
 
A shot in the dark, because "On Error.." should cure it, addition to Dave's
code:
dim wkbk as workbook
.....
Application.DisplayAlerts=False
set wkbk = nothing
on error resume next
set wkbk = workbooks.open(filename:=file, ..., password:="IncorrectPassword")
on error goto 0

if wkbk is nothing then
'workbook didn't open
else
'do the real work
end if
Application.DisplayAlerts=True

Regards,
The Code Cage Team
www.thecodecage.com/forumz
 
Back
Top