PC Review


Reply
Thread Tools Rate Thread

Cancel 'Password' prompt during VBA

 
 
=?Utf-8?B?U2hpbW1lc3M=?=
Guest
Posts: n/a
 
      28th Dec 2006
I run VB code to cycle through a group of excel files and chenge their
properties using the below code:

For i = 1 To .FoundFiles.Count
Set wb = Workbooks.Open(Filename:=.FoundFiles(i))

Sometimes a file opens with the following:

Password
Enter password for write access, or open read only.
Password:_________
Cancel
Read Only

Is there a way for VB to hit cancel if this dialogue box appears?
 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      28th Dec 2006
Maybe:

For i = 1 To .FoundFiles.Count
set wb = nothing
on error resume next
Set wb = Workbooks.Open(Filename:=.FoundFiles(i), password:="")
on error goto 0
if wb is nothing then
'don't do anything, it wasn't opened!
else
'do your real work here
end if
next i


Shimmess wrote:
>
> I run VB code to cycle through a group of excel files and chenge their
> properties using the below code:
>
> For i = 1 To .FoundFiles.Count
> Set wb = Workbooks.Open(Filename:=.FoundFiles(i))
>
> Sometimes a file opens with the following:
>
> Password
> Enter password for write access, or open read only.
> Password:_________
> Cancel
> Read Only
>
> Is there a way for VB to hit cancel if this dialogue box appears?


--

Dave Peterson
 
Reply With Quote
 
=?Utf-8?B?U2hpbW1lc3M=?=
Guest
Posts: n/a
 
      28th Dec 2006
Didn't work. Still prompted me and when I hit cancel I get the following:

Run-Time error '1004':
Application-defined or object-defined error

Any suggestions?

"Dave Peterson" wrote:

> Maybe:
>
> For i = 1 To .FoundFiles.Count
> set wb = nothing
> on error resume next
> Set wb = Workbooks.Open(Filename:=.FoundFiles(i), password:="")
> on error goto 0
> if wb is nothing then
> 'don't do anything, it wasn't opened!
> else
> 'do your real work here
> end if
> next i
>
>
> Shimmess wrote:
> >
> > I run VB code to cycle through a group of excel files and chenge their
> > properties using the below code:
> >
> > For i = 1 To .FoundFiles.Count
> > Set wb = Workbooks.Open(Filename:=.FoundFiles(i))
> >
> > Sometimes a file opens with the following:
> >
> > Password
> > Enter password for write access, or open read only.
> > Password:_________
> > Cancel
> > Read Only
> >
> > Is there a way for VB to hit cancel if this dialogue box appears?

>
> --
>
> Dave Peterson
>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      28th Dec 2006
I think you changed the suggested code.

If you did, you'll want to post your new version--or try it again with the
suggested code.



Shimmess wrote:
>
> Didn't work. Still prompted me and when I hit cancel I get the following:
>
> Run-Time error '1004':
> Application-defined or object-defined error
>
> Any suggestions?
>
> "Dave Peterson" wrote:
>
> > Maybe:
> >
> > For i = 1 To .FoundFiles.Count
> > set wb = nothing
> > on error resume next
> > Set wb = Workbooks.Open(Filename:=.FoundFiles(i), password:="")
> > on error goto 0
> > if wb is nothing then
> > 'don't do anything, it wasn't opened!
> > else
> > 'do your real work here
> > end if
> > next i
> >
> >
> > Shimmess wrote:
> > >
> > > I run VB code to cycle through a group of excel files and chenge their
> > > properties using the below code:
> > >
> > > For i = 1 To .FoundFiles.Count
> > > Set wb = Workbooks.Open(Filename:=.FoundFiles(i))
> > >
> > > Sometimes a file opens with the following:
> > >
> > > Password
> > > Enter password for write access, or open read only.
> > > Password:_________
> > > Cancel
> > > Read Only
> > >
> > > Is there a way for VB to hit cancel if this dialogue box appears?

> >
> > --
> >
> > Dave Peterson
> >


--

Dave Peterson
 
Reply With Quote
 
=?Utf-8?B?U2hpbW1lc3M=?=
Guest
Posts: n/a
 
      28th Dec 2006
Thanks for your help Dave.

The below works so that when I press 'read only' it closes the file and move
on. I want to be able to suppress the dialogue box completely so the code
doesn't stop:

For i = 1 To .FoundFiles.Count
Set wb = Workbooks.Open(Filename:=.FoundFiles(i), ReadOnly:=False,
Password:="")
On Error GoTo 0
If wb.ReadOnly Then
wb.Close
RO = RO + 1
Else
'do work here
end if
next i

"Dave Peterson" wrote:

> I think you changed the suggested code.
>
> If you did, you'll want to post your new version--or try it again with the
> suggested code.
>
>
>
> Shimmess wrote:
> >
> > Didn't work. Still prompted me and when I hit cancel I get the following:
> >
> > Run-Time error '1004':
> > Application-defined or object-defined error
> >
> > Any suggestions?
> >
> > "Dave Peterson" wrote:
> >
> > > Maybe:
> > >
> > > For i = 1 To .FoundFiles.Count
> > > set wb = nothing
> > > on error resume next
> > > Set wb = Workbooks.Open(Filename:=.FoundFiles(i), password:="")
> > > on error goto 0
> > > if wb is nothing then
> > > 'don't do anything, it wasn't opened!
> > > else
> > > 'do your real work here
> > > end if
> > > next i
> > >
> > >
> > > Shimmess wrote:
> > > >
> > > > I run VB code to cycle through a group of excel files and chenge their
> > > > properties using the below code:
> > > >
> > > > For i = 1 To .FoundFiles.Count
> > > > Set wb = Workbooks.Open(Filename:=.FoundFiles(i))
> > > >
> > > > Sometimes a file opens with the following:
> > > >
> > > > Password
> > > > Enter password for write access, or open read only.
> > > > Password:_________
> > > > Cancel
> > > > Read Only
> > > >
> > > > Is there a way for VB to hit cancel if this dialogue box appears?
> > >
> > > --
> > >
> > > Dave Peterson
> > >

>
> --
>
> Dave Peterson
>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      28th Dec 2006
Maybe you can use this:

For i = 1 To .FoundFiles.Count
Set wb = Nothing
On Error Resume Next
Set wb = Workbooks.Open(Filename:=.FoundFiles(i), _
Password:="", writerespassword:="")
On Error GoTo 0
If wb Is Nothing Then
'don't do anything, it wasn't opened!
MsgBox "not opened"
Else
'do your real work here
MsgBox "it's open"
End If
Next i

Don't delete those lines at the top ("set wb = nothing" and "On error resume
next"). They're important.



Shimmess wrote:
>
> Thanks for your help Dave.
>
> The below works so that when I press 'read only' it closes the file and move
> on. I want to be able to suppress the dialogue box completely so the code
> doesn't stop:
>
> For i = 1 To .FoundFiles.Count
> Set wb = Workbooks.Open(Filename:=.FoundFiles(i), ReadOnly:=False,
> Password:="")
> On Error GoTo 0
> If wb.ReadOnly Then
> wb.Close
> RO = RO + 1
> Else
> 'do work here
> end if
> next i
>
> "Dave Peterson" wrote:
>
> > I think you changed the suggested code.
> >
> > If you did, you'll want to post your new version--or try it again with the
> > suggested code.
> >
> >
> >
> > Shimmess wrote:
> > >
> > > Didn't work. Still prompted me and when I hit cancel I get the following:
> > >
> > > Run-Time error '1004':
> > > Application-defined or object-defined error
> > >
> > > Any suggestions?
> > >
> > > "Dave Peterson" wrote:
> > >
> > > > Maybe:
> > > >
> > > > For i = 1 To .FoundFiles.Count
> > > > set wb = nothing
> > > > on error resume next
> > > > Set wb = Workbooks.Open(Filename:=.FoundFiles(i), password:="")
> > > > on error goto 0
> > > > if wb is nothing then
> > > > 'don't do anything, it wasn't opened!
> > > > else
> > > > 'do your real work here
> > > > end if
> > > > next i
> > > >
> > > >
> > > > Shimmess wrote:
> > > > >
> > > > > I run VB code to cycle through a group of excel files and chenge their
> > > > > properties using the below code:
> > > > >
> > > > > For i = 1 To .FoundFiles.Count
> > > > > Set wb = Workbooks.Open(Filename:=.FoundFiles(i))
> > > > >
> > > > > Sometimes a file opens with the following:
> > > > >
> > > > > Password
> > > > > Enter password for write access, or open read only.
> > > > > Password:_________
> > > > > Cancel
> > > > > Read Only
> > > > >
> > > > > Is there a way for VB to hit cancel if this dialogue box appears?
> > > >
> > > > --
> > > >
> > > > Dave Peterson
> > > >

> >
> > --
> >
> > Dave Peterson
> >


--

Dave Peterson
 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      28th Dec 2006
ps. I still think that the first suggestion is what you want, but the
writerespassword probably won't matter????

Dave Peterson wrote:
>
> Maybe you can use this:
>
> For i = 1 To .FoundFiles.Count
> Set wb = Nothing
> On Error Resume Next
> Set wb = Workbooks.Open(Filename:=.FoundFiles(i), _
> Password:="", writerespassword:="")
> On Error GoTo 0
> If wb Is Nothing Then
> 'don't do anything, it wasn't opened!
> MsgBox "not opened"
> Else
> 'do your real work here
> MsgBox "it's open"
> End If
> Next i
>
> Don't delete those lines at the top ("set wb = nothing" and "On error resume
> next"). They're important.
>
> Shimmess wrote:
> >
> > Thanks for your help Dave.
> >
> > The below works so that when I press 'read only' it closes the file and move
> > on. I want to be able to suppress the dialogue box completely so the code
> > doesn't stop:
> >
> > For i = 1 To .FoundFiles.Count
> > Set wb = Workbooks.Open(Filename:=.FoundFiles(i), ReadOnly:=False,
> > Password:="")
> > On Error GoTo 0
> > If wb.ReadOnly Then
> > wb.Close
> > RO = RO + 1
> > Else
> > 'do work here
> > end if
> > next i
> >
> > "Dave Peterson" wrote:
> >
> > > I think you changed the suggested code.
> > >
> > > If you did, you'll want to post your new version--or try it again with the
> > > suggested code.
> > >
> > >
> > >
> > > Shimmess wrote:
> > > >
> > > > Didn't work. Still prompted me and when I hit cancel I get the following:
> > > >
> > > > Run-Time error '1004':
> > > > Application-defined or object-defined error
> > > >
> > > > Any suggestions?
> > > >
> > > > "Dave Peterson" wrote:
> > > >
> > > > > Maybe:
> > > > >
> > > > > For i = 1 To .FoundFiles.Count
> > > > > set wb = nothing
> > > > > on error resume next
> > > > > Set wb = Workbooks.Open(Filename:=.FoundFiles(i), password:="")
> > > > > on error goto 0
> > > > > if wb is nothing then
> > > > > 'don't do anything, it wasn't opened!
> > > > > else
> > > > > 'do your real work here
> > > > > end if
> > > > > next i
> > > > >
> > > > >
> > > > > Shimmess wrote:
> > > > > >
> > > > > > I run VB code to cycle through a group of excel files and chenge their
> > > > > > properties using the below code:
> > > > > >
> > > > > > For i = 1 To .FoundFiles.Count
> > > > > > Set wb = Workbooks.Open(Filename:=.FoundFiles(i))
> > > > > >
> > > > > > Sometimes a file opens with the following:
> > > > > >
> > > > > > Password
> > > > > > Enter password for write access, or open read only.
> > > > > > Password:_________
> > > > > > Cancel
> > > > > > Read Only
> > > > > >
> > > > > > Is there a way for VB to hit cancel if this dialogue box appears?
> > > > >
> > > > > --
> > > > >
> > > > > Dave Peterson
> > > > >
> > >
> > > --
> > >
> > > Dave Peterson
> > >

>
> --
>
> Dave Peterson


--

Dave Peterson
 
Reply With Quote
 
=?Utf-8?B?U2hpbW1lc3M=?=
Guest
Posts: n/a
 
      28th Dec 2006
That worked great! Thanks Dave!

"Dave Peterson" wrote:

> ps. I still think that the first suggestion is what you want, but the
> writerespassword probably won't matter????
>
> Dave Peterson wrote:
> >
> > Maybe you can use this:
> >
> > For i = 1 To .FoundFiles.Count
> > Set wb = Nothing
> > On Error Resume Next
> > Set wb = Workbooks.Open(Filename:=.FoundFiles(i), _
> > Password:="", writerespassword:="")
> > On Error GoTo 0
> > If wb Is Nothing Then
> > 'don't do anything, it wasn't opened!
> > MsgBox "not opened"
> > Else
> > 'do your real work here
> > MsgBox "it's open"
> > End If
> > Next i
> >
> > Don't delete those lines at the top ("set wb = nothing" and "On error resume
> > next"). They're important.
> >
> > Shimmess wrote:
> > >
> > > Thanks for your help Dave.
> > >
> > > The below works so that when I press 'read only' it closes the file and move
> > > on. I want to be able to suppress the dialogue box completely so the code
> > > doesn't stop:
> > >
> > > For i = 1 To .FoundFiles.Count
> > > Set wb = Workbooks.Open(Filename:=.FoundFiles(i), ReadOnly:=False,
> > > Password:="")
> > > On Error GoTo 0
> > > If wb.ReadOnly Then
> > > wb.Close
> > > RO = RO + 1
> > > Else
> > > 'do work here
> > > end if
> > > next i
> > >
> > > "Dave Peterson" wrote:
> > >
> > > > I think you changed the suggested code.
> > > >
> > > > If you did, you'll want to post your new version--or try it again with the
> > > > suggested code.
> > > >
> > > >
> > > >
> > > > Shimmess wrote:
> > > > >
> > > > > Didn't work. Still prompted me and when I hit cancel I get the following:
> > > > >
> > > > > Run-Time error '1004':
> > > > > Application-defined or object-defined error
> > > > >
> > > > > Any suggestions?
> > > > >
> > > > > "Dave Peterson" wrote:
> > > > >
> > > > > > Maybe:
> > > > > >
> > > > > > For i = 1 To .FoundFiles.Count
> > > > > > set wb = nothing
> > > > > > on error resume next
> > > > > > Set wb = Workbooks.Open(Filename:=.FoundFiles(i), password:="")
> > > > > > on error goto 0
> > > > > > if wb is nothing then
> > > > > > 'don't do anything, it wasn't opened!
> > > > > > else
> > > > > > 'do your real work here
> > > > > > end if
> > > > > > next i
> > > > > >
> > > > > >
> > > > > > Shimmess wrote:
> > > > > > >
> > > > > > > I run VB code to cycle through a group of excel files and chenge their
> > > > > > > properties using the below code:
> > > > > > >
> > > > > > > For i = 1 To .FoundFiles.Count
> > > > > > > Set wb = Workbooks.Open(Filename:=.FoundFiles(i))
> > > > > > >
> > > > > > > Sometimes a file opens with the following:
> > > > > > >
> > > > > > > Password
> > > > > > > Enter password for write access, or open read only.
> > > > > > > Password:_________
> > > > > > > Cancel
> > > > > > > Read Only
> > > > > > >
> > > > > > > Is there a way for VB to hit cancel if this dialogue box appears?
> > > > > >
> > > > > > --
> > > > > >
> > > > > > Dave Peterson
> > > > > >
> > > >
> > > > --
> > > >
> > > > Dave Peterson
> > > >

> >
> > --
> >
> > Dave Peterson

>
> --
>
> Dave Peterson
>

 
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
'Cancel' on User Prompt Box kmzito@gmail.com Microsoft Excel Programming 2 12th May 2009 02:12 AM
VBScript to prompt Save on Cancel click paperclip Microsoft Excel Programming 8 3rd Aug 2006 04:11 PM
cancel system login prompt Sam Microsoft Access ADP SQL Server 3 29th Nov 2005 04:10 PM
How can click 'Cancel' on parameter query prompt to have all the . =?Utf-8?B?eXdj?= Microsoft Access Queries 4 16th Feb 2005 12:46 PM
I GET ERROR WHEN CLICK ON CANCEL VBA PASSWORD PROMPT Ami Dalwadi Microsoft Access Security 1 11th Jun 2004 05:00 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:44 AM.