Coba bagian :
If newfile<>"" and newfile <> "false" then
Set wslama=workbooks.open(newfile,password:="abc")
Wsbaru.activate
End if
diberi tambahan error handler menjadi :
If newfile<>"" and newfile <> "false" then
on error resume next
application.displayalerts=false
Set wslama=workbooks.open(newfile,password:="abc")
application.displayalerts=true
if not wslama is nothing then
Wsbaru.activate
else
err.clear
on error goto 0
msgbox "bukan file yang harus dibuka. Pilih file
lain.",vbcrtitical,"Buka file khusus"
endif
End if
Wassalam,
Kid.
On Thu, Nov 29, 2012 at 10:06 AM, <[email protected]> wrote:
> **
>
>
> ** Hi all,
>
> Maaf kalau saya forward, krn spt nya belum ada yg merespon. Thanks in
> advance
> ------------------------------
> *From: * [email protected]
> *Sender: * [email protected]
> *Date: *Wed, 28 Nov 2012 08:05:02 +0000
> *To: *<[email protected]>
> *ReplyTo: * [email protected]
> *Subject: *[belajar-excel] trap if fail to open password protected excel
>
>
>
> Hi all,
>
> Saya sedang membuat macro otomatis membuka file excel yg terpassword.
>
> Bagaimana trap nya jika user salah pilih file yg berpassword "ab" atau
> lainnya
>
> Private sub cmb_click()
> Dim newfile as string
> Dim newfiletype as string
> Dim newfilename as string
> Dim wslama as workbook
> Dim wsbaru as workbook
>
> Newfiletype = "excel files 1997-2003 (*.xls), *.xls, " & "all files (*.*),
> *.*"
> Newfile =
> application.getsaveasfilename(initialfilename:=newfilename,filefilter:=newfiletype)
>
> If newfile<>"" and newfile <> "false" then
> Set wslama=workbooks.open(newfile,password:="abc")
> Wsbaru.activate
> End if
> End sub
>
>
>