Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,069
Default dont open a Workbook is Password protected

Hi all,

How can i error trap opening a workbook from VB if the Workbook is Password
protected? I'm using:

Workbooks.open WB, Updatelinks:=False, ReasOnly:=True
I'm thinking maybe i have to have an error handler somewhere but dont know
what to write. Any help as always greatly appreciated.

Thanks.
John
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default dont open a Workbook is Password protected

Dim wkbk as workbook
dim teststr as string
dim wb as string
wb = "C:\somefolder\filename.xls"

teststr = ""
on error resume next
teststr = dir(wb)
on error goto 0

if teststr = "" then
msgbox "File not found!"
exit sub
end if

set wkbk = nothing
on error resume next
set wkbk = workbooks.open(filename:=wb, readonly:=true, updatelinks:=0)
on error goto 0

if wkbk is nothing then
msgbox wb & " wasn't opened
exit sub '???
end if



John wrote:

Hi all,

How can i error trap opening a workbook from VB if the Workbook is Password
protected? I'm using:

Workbooks.open WB, Updatelinks:=False, ReasOnly:=True
I'm thinking maybe i have to have an error handler somewhere but dont know
what to write. Any help as always greatly appreciated.

Thanks.
John


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default dont open a Workbook is Password protected


Something like:

Code:
--------------------
If Err.Number = 70 Then GoTo Nxt
'Your code
Nxt:
--------------------


John;385733 Wrote:
Hi all,

How can i error trap opening a workbook from VB if the Workbook is
Password
protected? I'm using:

Workbooks.open WB, Updatelinks:=False, ReasOnly:=True
I'm thinking maybe i have to have an error handler somewhere but dont
know
what to write. Any help as always greatly appreciated.

Thanks.
John



--
Simon Lloyd

Regards,
Simon Lloyd
'The Code Cage' (http://www.thecodecage.com)
------------------------------------------------------------------------
Simon Lloyd's Profile: http://www.thecodecage.com/forumz/member.php?userid=1
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=107859

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,049
Default dont open a Workbook is Password protected

handle the error in a function

' so in your main code ....

dim newWB as workbook

if WBopened(WB) then
'ok and newWB is the workbook object
' and do stuff
'finally
newWB.Close False ' to close without saving
set newWB = Nothing
else
'oops
end if


end sub

then add the function...
' the function is passed the workbook name and the wbobject
' if succesful , the boolrean is true and the object is set to th eworkbook
' if not succesful the boolean is false

function WBopened(WB as string, newbook as Workbook) as boolean
on error resume next
set newbook = Workbooks.open( WB, Updatelinks:=False, ReasOnly:=True)
if err.Number=0 then
err.clear
else
WBopened = true
end if
on error goto 0
end function





"John" wrote in message
...
Hi all,

How can i error trap opening a workbook from VB if the Workbook is
Password
protected? I'm using:

Workbooks.open WB, Updatelinks:=False, ReasOnly:=True
I'm thinking maybe i have to have an error handler somewhere but dont know
what to write. Any help as always greatly appreciated.

Thanks.
John


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
Make Workbook Password protected tp open Stockwell43 Excel Discussion (Misc queries) 4 July 2nd 08 12:44 AM
vba macro open password protected workbook Ray Excel Programming 2 March 31st 06 04:10 PM
Open workbook that is protected with password ianripping[_67_] Excel Programming 2 June 1st 04 11:48 AM
Open password protected workbook. Tom Excel Programming 3 April 16th 04 03:43 PM
Open a password protected excel workbook from second workbook to fetch data using dynamic connection kaustav choudhury Excel Programming 2 April 3rd 04 06:18 AM


All times are GMT +1. The time now is 01:51 AM.

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

About Us

"It's about Microsoft Excel"