ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Stopping error messages from popping up - part 2 (https://www.excelbanter.com/excel-programming/358738-stopping-error-messages-popping-up-part-2-a.html)

phil-rge-ee

Stopping error messages from popping up - part 2
 
Ok, I got another one. I click on a button and it runs this code:

Private Sub cmdEnterScores_Click()
ChDir "C:\WINDOWS"
Workbooks.Open FileName:="C:\WINDOWS\datasheet2006.xls"
(more non-important code here)

If the datasheet2006.xls does not exist I get a VB error telling me so and
the script halts. How do I code it so that if the datasheet.xls does not
exist I can pop up my own msgbox instead of the vb script error box?

Thanks,
Phil

Dave Peterson

Stopping error messages from popping up - part 2
 
First, I wouldn't put any of my files in the C:\windows folder. That folder is
made for system stuff. And there's too much of a chance that I may "clean up"
too much when I clean up my stuff.


dim TestStr as string
dim myFileName as string

myfilename = "C:\windows\datasheet2006.xls"

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

if teststr = "" then
msgbox "Not found"
else
msgbox "Found it"
end if



phil-rge-ee wrote:

Ok, I got another one. I click on a button and it runs this code:

Private Sub cmdEnterScores_Click()
ChDir "C:\WINDOWS"
Workbooks.Open FileName:="C:\WINDOWS\datasheet2006.xls"
(more non-important code here)

If the datasheet2006.xls does not exist I get a VB error telling me so and
the script halts. How do I code it so that if the datasheet.xls does not
exist I can pop up my own msgbox instead of the vb script error box?

Thanks,
Phil


--

Dave Peterson

phil-rge-ee

Stopping error messages from popping up - part 2
 
I put it in the windows folder so it could be somewhat hidden so people
"cleaning up" their computers wouldn't see it and delete it, thinking they
wouldn't dare delete something from the windows folder, but alas, some still
see this file, think they don't need it and delete it. I'm thinking of moving
it to another location, but I also want to have this popup come up if the
file does get deleted "by accident".

Thanks for the help.
Phil

"Dave Peterson" wrote:

First, I wouldn't put any of my files in the C:\windows folder. That folder is
made for system stuff. And there's too much of a chance that I may "clean up"
too much when I clean up my stuff.


dim TestStr as string
dim myFileName as string

myfilename = "C:\windows\datasheet2006.xls"

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

if teststr = "" then
msgbox "Not found"
else
msgbox "Found it"
end if



phil-rge-ee wrote:

Ok, I got another one. I click on a button and it runs this code:

Private Sub cmdEnterScores_Click()
ChDir "C:\WINDOWS"
Workbooks.Open FileName:="C:\WINDOWS\datasheet2006.xls"
(more non-important code here)

If the datasheet2006.xls does not exist I get a VB error telling me so and
the script halts. How do I code it so that if the datasheet.xls does not
exist I can pop up my own msgbox instead of the vb script error box?

Thanks,
Phil


--

Dave Peterson



All times are GMT +1. The time now is 06:00 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com