By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,804 Members | 1,358 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,804 IT Pros & Developers. It's quick & easy.

Error handling

P: n/a
Ive written a pretty basic program for work that offers the user a number of
buttons to selct that then open an Excel Template.

The code is basically as shown below, the first section sets the base path
for the Templates and gives the user the option to cahnge should the network
position move. The second part is the code for loading the file on
activation of the corresponding button.

All very simple and functional.

What it doesnt od though is raise an error if the template does not exist.

I would be grateful if someone could give me a clue as to how to go about
this.

Private Sub Menu_Click()
Dim sNewPath As String

sNewPath = InputBox("Enter new location of template files:", ,
"\\agb-dds01\hdd3\Request-templates\")

If Len(Trim(sNewPath)) > 0 Then
m_sBasePath = sNewPath
MsgBox "Base Path changed."
End If
End Sub

Private Sub Command1_Click()

If Right$(m_sBasePath, 1) <> "\" Then
m_sBasePath = m_sBasePath & "\"
End If

ShellEx m_sBasePath & "Static Airbag Template.xlt", , , , "open",
Me.hWnd
Unload Me

End Sub

Drink and drugs cause amnesia and other things I can't remember... Another
meaningless e-mail brought to you by Dave Wateridge PLC. A member of the Sad
Bastard Group

http://uk.geocities.com/da************@btinternet.com/
http://www.btinternet.com/~fratton/
Jul 17 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a

"Spudgun" <no*@here.com> wrote in message
news:ch**********@hercules.btinternet.com...
| Ive written a pretty basic program for work that offers the user a
number of
| buttons to selct that then open an Excel Template.
|
| The code is basically as shown below, the first section sets the base
path
| for the Templates and gives the user the option to cahnge should the
network
| position move. The second part is the code for loading the file on
| activation of the corresponding button.
|
| All very simple and functional.
|
| What it doesnt od though is raise an error if the template does not
exist.
|
| I would be grateful if someone could give me a clue as to how to go
about
| this.
|

If Dir(m_sBasePath & "Static Airbag Template.xlt") = "" Then
Msgbox "Can't find " & m_sBasePath & "Static Airbag Template.xlt"
Else
ShellEx m_sBasePath & "Static Airbag Template.xlt", , , , "open",
Me.hWnd
End If
Jul 17 '05 #2

P: n/a
Using that code returned the following error message

Run time error 52 - bad file name or number, this relates to the line
starting If Dir(m_s....etc

I almost had a psychic girlfriend but she left me before we met. Another
meaningless e-mail brought to you by Dave Wateridge PLC. A member of the Sad
Bastard Group

http://uk.geocities.com/da************@btinternet.com/
http://www.btinternet.com/~fratton/

"Steve Gerrard" <my********@comcast.net> wrote in message
news:Qu********************@comcast.com...

"Spudgun" <no*@here.com> wrote in message
news:ch**********@hercules.btinternet.com...
| Ive written a pretty basic program for work that offers the user a
number of
| buttons to selct that then open an Excel Template.
|
| The code is basically as shown below, the first section sets the base
path
| for the Templates and gives the user the option to cahnge should the
network
| position move. The second part is the code for loading the file on
| activation of the corresponding button.
|
| All very simple and functional.
|
| What it doesnt od though is raise an error if the template does not
exist.
|
| I would be grateful if someone could give me a clue as to how to go
about
| this.
|

If Dir(m_sBasePath & "Static Airbag Template.xlt") = "" Then
Msgbox "Can't find " & m_sBasePath & "Static Airbag Template.xlt"
Else
ShellEx m_sBasePath & "Static Airbag Template.xlt", , , , "open",
Me.hWnd
End If

Jul 17 '05 #3

P: n/a
Steve Gerrard wrote:
"Spudgun" <no*@here.com> wrote in message
news:ch**********@hercules.btinternet.com...
| Ive written a pretty basic program for work that offers the user a
number of
| buttons to selct that then open an Excel Template.
|
| The code is basically as shown below, the first section sets the base
path
| for the Templates and gives the user the option to cahnge should the
network
| position move. The second part is the code for loading the file on
| activation of the corresponding button.
|
| All very simple and functional.
|
| What it doesnt od though is raise an error if the template does not
exist.
|
| I would be grateful if someone could give me a clue as to how to go
about
| this.
|

If Dir(m_sBasePath & "Static Airbag Template.xlt") = "" Then
Msgbox "Can't find " & m_sBasePath & "Static Airbag Template.xlt"
Else
ShellEx m_sBasePath & "Static Airbag Template.xlt", , , , "open",
Me.hWnd
End If

G'day Steve,
Sorry to jump into someone else's thread.
2 quick questions.
1). Why the "Me.hWnd"?
2). How would I check if a folder existed?
tia
build
Jul 17 '05 #4

P: n/a

"build" <bu*****@datafast.net.au> wrote in message
news:41********@news.alphalink.com.au...
| Steve Gerrard wrote:
|
| > If Dir(m_sBasePath & "Static Airbag Template.xlt") = "" Then
| > Msgbox "Can't find " & m_sBasePath & "Static Airbag
Template.xlt"
| > Else
| > ShellEx m_sBasePath & "Static Airbag Template.xlt", , , ,
"open",
| > Me.hWnd
| > End If
| >
| G'day Steve,
| Sorry to jump into someone else's thread.
| 2 quick questions.
| 1). Why the "Me.hWnd"?
| 2). How would I check if a folder existed?
| tia
| build

1. ShellEx is a Windows API call. If a Windows API call asks for a
window handle, you give it a window handle, and don't ask why. :)

2. Here is a simple function demonstrating use of Dir and GetAttr:

Private Sub Command1_Click()
CheckPath "C:\Program Files"
CheckPath "C:\Windows\notepad.exe"
CheckPath "Sheer Nonsense"
End Sub

Private Sub CheckPath(Path As String)
If Dir(Path, vbDirectory) = "" Then
MsgBox Path & " not found"
ElseIf (GetAttr(Path) And vbDirectory) = 0 Then
MsgBox Path & " is a file"
Else
MsgBox Path & " is a folder"
End If
End Sub

Jul 17 '05 #5

P: n/a
Steve Gerrard wrote:
"build" <bu*****@datafast.net.au> wrote in message
news:41********@news.alphalink.com.au...
| Steve Gerrard wrote:
| > If Dir(m_sBasePath & "Static Airbag Template.xlt") = "" Then
| > Msgbox "Can't find " & m_sBasePath & "Static Airbag
| > Template.xlt"
| > Else
| > ShellEx m_sBasePath & "Static Airbag Template.xlt", , , ,
| > "open",
| > Me.hWnd
| > End If
| >
| G'day Steve,
| Sorry to jump into someone else's thread.
| 2 quick questions.
| 1). Why the "Me.hWnd"?
| 2). How would I check if a folder existed?
| tia
| build

1. ShellEx is a Windows API call. If a Windows API call asks for a
window handle, you give it a window handle, and don't ask why. :)

2. Here is a simple function demonstrating use of Dir and GetAttr:

Private Sub Command1_Click()
CheckPath "C:\Program Files"
CheckPath "C:\Windows\notepad.exe"
CheckPath "Sheer Nonsense"
End Sub

Private Sub CheckPath(Path As String)
If Dir(Path, vbDirectory) = "" Then
MsgBox Path & " not found"
ElseIf (GetAttr(Path) And vbDirectory) = 0 Then
MsgBox Path & " is a file"
Else
MsgBox Path & " is a folder"
End If
End Sub

Thx Steve, just what I was after, appreciate your taking the time :-)
Jul 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.