-
Password-protected Excel workbook...
Hi --
I'm trying to find out if the workbook I'm about to open is password
protected. The workbook object has a HasPassword property for this, however,
I need to open the workbook in order to make the property call, which I
can't if it's password-protected! This is what I have:
Dim objApp As Excel.Application
Dim objXlWb As Excel.Workbook
Set objApp = New Excel.Application
'this will prompt the user for a password (which I don't want - I want
to know if it has a password first, and if it does, not do anything with
the file)
Set objXlWb = objApp.Workbooks.Open("c:\test.xls")
If objXlWb.HasPassword Then
MsgBox "Has password!"
Else
MsgBox "No password!"
End If
I could do an 'On...Error...Resume...Next', supply a zero-length string for
the password each time I open a workbook, then check the error number to see
if it's a password error, but this seems uneccessary. That also begs the
question: what is the HasPassword property for then?
Is there something else I could do?
Thanks!
-
Re: Password-protected Excel workbook...
hei, there
good question for you:
do you know how to convert a xla file back to xls file? the xla file I was
trying to open is " unviewable" , so I guess I have to convert it back to
xls then to open and edit it.....
thanks
----------
"Matt Markus" <matt_markus@hotmail.com> wrote:
>Hi --
>
>I'm trying to find out if the workbook I'm about to open is password
>protected. The workbook object has a HasPassword property for this, however,
>I need to open the workbook in order to make the property call, which I
>can't if it's password-protected! This is what I have:
>
> Dim objApp As Excel.Application
> Dim objXlWb As Excel.Workbook
>
> Set objApp = New Excel.Application
>
> 'this will prompt the user for a password (which I don't want - I want
>to know if it has a password first, and if it does, not do anything
with
>the file)
> Set objXlWb = objApp.Workbooks.Open("c:\test.xls")
>
> If objXlWb.HasPassword Then
> MsgBox "Has password!"
> Else
> MsgBox "No password!"
> End If
>
>I could do an 'On...Error...Resume...Next', supply a zero-length string
for
>the password each time I open a workbook, then check the error number to
see
>if it's a password error, but this seems uneccessary. That also begs the
>question: what is the HasPassword property for then?
>
>Is there something else I could do?
>
>Thanks!
>
>
>
-
Re: Password-protected Excel workbook...
Hendry,
You can't convert an Excel addin back into an Excel workbook. This is
why your supposed to save a backup copy of your workbook (different name)
before you change it into an addin. If you fail to do so, you effectively
can't alter the addin in anyway, unless you remake it from scratch.
Chris Lucas
"Hendry" <hendry.tong@hotmail.com> wrote:
>
>hei, there
>good question for you:
>do you know how to convert a xla file back to xls file? the xla file I was
>trying to open is " unviewable" , so I guess I have to convert it back to
>xls then to open and edit it.....
>thanks
>----------
>
>
>"Matt Markus" <matt_markus@hotmail.com> wrote:
>>Hi --
>>
>>I'm trying to find out if the workbook I'm about to open is password
>>protected. The workbook object has a HasPassword property for this, however,
>>I need to open the workbook in order to make the property call, which I
>>can't if it's password-protected! This is what I have:
>>
>> Dim objApp As Excel.Application
>> Dim objXlWb As Excel.Workbook
>>
>> Set objApp = New Excel.Application
>>
>> 'this will prompt the user for a password (which I don't want - I want
>>to know if it has a password first, and if it does, not do anything
>with
>>the file)
>> Set objXlWb = objApp.Workbooks.Open("c:\test.xls")
>>
>> If objXlWb.HasPassword Then
>> MsgBox "Has password!"
>> Else
>> MsgBox "No password!"
>> End If
>>
>>I could do an 'On...Error...Resume...Next', supply a zero-length string
>for
>>the password each time I open a workbook, then check the error number to
>see
>>if it's a password error, but this seems uneccessary. That also begs the
>>question: what is the HasPassword property for then?
>>
>>Is there something else I could do?
>>
>>Thanks!
>>
>>
>>
>
-
Re: Password-protected Excel workbook...
What does this have to do with my question?
"Hendry" <hendry.tong@hotmail.com> wrote in message
news:3bd87f57$1@news.devx.com...
>
> hei, there
> good question for you:
> do you know how to convert a xla file back to xls file? the xla file I was
> trying to open is " unviewable" , so I guess I have to convert it back to
> xls then to open and edit it.....
> thanks
> ----------
>
>
> "Matt Markus" <matt_markus@hotmail.com> wrote:
> >Hi --
> >
> >I'm trying to find out if the workbook I'm about to open is password
> >protected. The workbook object has a HasPassword property for this,
however,
> >I need to open the workbook in order to make the property call, which I
> >can't if it's password-protected! This is what I have:
> >
> > Dim objApp As Excel.Application
> > Dim objXlWb As Excel.Workbook
> >
> > Set objApp = New Excel.Application
> >
> > 'this will prompt the user for a password (which I don't want - I
want
> >to know if it has a password first, and if it does, not do anything
> with
> >the file)
> > Set objXlWb = objApp.Workbooks.Open("c:\test.xls")
> >
> > If objXlWb.HasPassword Then
> > MsgBox "Has password!"
> > Else
> > MsgBox "No password!"
> > End If
> >
> >I could do an 'On...Error...Resume...Next', supply a zero-length string
> for
> >the password each time I open a workbook, then check the error number to
> see
> >if it's a password error, but this seems uneccessary. That also begs the
> >question: what is the HasPassword property for then?
> >
> >Is there something else I could do?
> >
> >Thanks!
> >
> >
> >
>
-
Re: Password-protected Excel workbook...
On Thu, 25 Oct 2001 14:02:39 -0400, "Matt Markus" <matt_markus@hotmail.com> wrote:
¤ Hi --
¤
¤ I'm trying to find out if the workbook I'm about to open is password
¤ protected. The workbook object has a HasPassword property for this, however,
¤ I need to open the workbook in order to make the property call, which I
¤ can't if it's password-protected! This is what I have:
¤
¤ Dim objApp As Excel.Application
¤ Dim objXlWb As Excel.Workbook
¤
¤ Set objApp = New Excel.Application
¤
¤ 'this will prompt the user for a password (which I don't want - I want
¤ to know if it has a password first, and if it does, not do anything with
¤ the file)
¤ Set objXlWb = objApp.Workbooks.Open("c:\test.xls")
¤
¤ If objXlWb.HasPassword Then
¤ MsgBox "Has password!"
¤ Else
¤ MsgBox "No password!"
¤ End If
¤
¤ I could do an 'On...Error...Resume...Next', supply a zero-length string for
¤ the password each time I open a workbook, then check the error number to see
¤ if it's a password error, but this seems uneccessary. That also begs the
¤ question: what is the HasPassword property for then?
¤
¤ Is there something else I could do?
For an "Open" password not sure if there is a better way to do it other than attempting to open it
with a bad password and then trapping the error:
Const BAD_PASSWORD_ERROR = 1004
On Error Resume Next
Application.Workbooks.Open "d:\My Documents\book2.xls", , , , "badpassword"
If Err.Number = BAD_PASSWORD_ERROR Then
MsgBox "This workbook requires a password"
End If
Paul ~~~ pclement@ameritech.net
Microsoft MVP (Visual Basic)
-
Re: Password-protected Excel workbook...
Hi Paul --
"Paul Clement" <UseAdddressAtEndofMessage@swspectrum.com> wrote in message
news:u62jtto3rblfh4m8j8gkafsdo002nf1vjv@4ax.com...
> On Thu, 25 Oct 2001 14:02:39 -0400, "Matt Markus"
<matt_markus@hotmail.com> wrote:
>
> ¤ Hi --
> ¤
> ¤ I'm trying to find out if the workbook I'm about to open is password
> ¤ protected. The workbook object has a HasPassword property for this,
however,
> ¤ I need to open the workbook in order to make the property call, which I
> ¤ can't if it's password-protected! This is what I have:
> ¤
> ¤ Dim objApp As Excel.Application
> ¤ Dim objXlWb As Excel.Workbook
> ¤
> ¤ Set objApp = New Excel.Application
> ¤
> ¤ 'this will prompt the user for a password (which I don't want - I
want
> ¤ to know if it has a password first, and if it does, not do anything
with
> ¤ the file)
> ¤ Set objXlWb = objApp.Workbooks.Open("c:\test.xls")
> ¤
> ¤ If objXlWb.HasPassword Then
> ¤ MsgBox "Has password!"
> ¤ Else
> ¤ MsgBox "No password!"
> ¤ End If
> ¤
> ¤ I could do an 'On...Error...Resume...Next', supply a zero-length string
for
> ¤ the password each time I open a workbook, then check the error number to
see
> ¤ if it's a password error, but this seems uneccessary. That also begs the
> ¤ question: what is the HasPassword property for then?
> ¤
> ¤ Is there something else I could do?
>
> For an "Open" password not sure if there is a better way to do it other
than attempting to open it
> with a bad password and then trapping the error:
>
> Const BAD_PASSWORD_ERROR = 1004
>
> On Error Resume Next
>
> Application.Workbooks.Open "d:\My Documents\book2.xls", , , ,
"badpassword"
> If Err.Number = BAD_PASSWORD_ERROR Then
> MsgBox "This workbook requires a password"
> End If
>
>
> Paul ~~~ pclement@ameritech.net
> Microsoft MVP (Visual Basic)
That's the only thing I could think of too (as shown in my orginal post),
but thanks for trying anyway.
Matt
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|