Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Cancel 'Password' prompt during VBA

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?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Cancel 'Password' prompt during VBA

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
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Cancel 'Password' prompt during VBA

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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Cancel 'Password' prompt during VBA

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
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Cancel 'Password' prompt during VBA

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



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Cancel 'Password' prompt during VBA

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
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Cancel 'Password' prompt during VBA

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
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Cancel 'Password' prompt during VBA

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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
msgbox yes=password & goto sheet3, no= cancel thunderhunter Excel Programming 3 September 27th 06 08:39 PM
VBScript to prompt Save on Cancel click paperclip[_2_] Excel Programming 8 August 3rd 06 04:11 PM
Password redundant through use of cancel Blokeyfella Excel Discussion (Misc queries) 1 February 1st 06 05:00 PM
How to CANCEL file SAVE PROMPT when MACRO is running? Stuart Macro Muppet Excel Discussion (Misc queries) 3 August 11th 05 12:26 PM
Password Prompt Noel Excel Discussion (Misc queries) 0 May 18th 05 07:42 PM


All times are GMT +1. The time now is 11:44 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"