View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
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