If & ElseIf statements

K

Kevin R

I need some help. I have the macro below but it is not working correctly. I want it to check the Startup Path of Word and then depending on the path it does 1 of 3 things. If it matches the first path, then it shows the form from modMyMenu. If it doesn't match the first but matches the second then it shows the form from modMyMenu2. If it doesn't match either then it displays a message. As it is now, it just jumping to the last and displaying the message even tho the startup path matches one of the first 2 items. What am I doing wrong?

Dim sPath

sPath = Options.DefaultFilePath(wdStartupPath)

If sPath = "C:\office\startup" Then
Application.Run MacroName:="modMyMenu.ShowFileForm"

ElseIf sPath = "C:\office_2\Startup" Then
Application.Run MacroName:="modMyMenu2.ShowFileForm"

Else
MsgBox "You have not set the Startup path for Word to the proper location. Consult your local systems administrator for assistance." _
, vbOKOnly, "Startup Path Error"

End If
 
T

Tom Lavedas

My guess is that it is a case sensitivity issue. Try changing the default path to one case, upper or lower, and structure your test to match that case, as in ...

sPath = Lower(Options.DefaultFilePath(wdStartupPath))
If sPath = "c:\office\startup" Then
Application.Run MacroName:="modMyMenu.ShowFileForm"
ElseIf sPath = "c:\office_2\startup" Then
Application.Run MacroName:="modMyMenu2.ShowFileForm"
Else
' ...
:

Tom Lavedas
 
K

Kevin R

I tried this but I get a compile error and it stops on the "Lower" like it doesn't recognize that. Is there another way?
 
J

Jezebel

The function you want is LCase(). Have you checked the value of sPath? Use a
MsgBox, or just step through the macro one line at a time (using F8) and
print the value of sPath in the immediate window.


Kevin R said:
I tried this but I get a compile error and it stops on the "Lower" like it
doesn't recognize that. Is there another way?default path to one case, upper or lower, and structure your test to match
that case, as in ...correctly. I want it to check the Startup Path of Word and then depending
on the path it does 1 of 3 things. If it matches the first path, then it
shows the form from modMyMenu. If it doesn't match the first but matches
the second then it shows the form from modMyMenu2. If it doesn't match
either then it displays a message. As it is now, it just jumping to the
last and displaying the message even tho the startup path matches one of the
first 2 items. What am I doing wrong?proper location. Consult your local systems administrator for assistance."
_
 
J

JB

Kevin said:
I need some help. I have the macro below but it is not working correctly. I want it to check the Startup Path of Word and then depending on the path it does 1 of 3 things. If it matches the first path, then it shows the form from modMyMenu. If it doesn't match the first but matches the second then it shows the form from modMyMenu2. If it doesn't match either then it displays a message. As it is now, it just jumping to the last and displaying the message even tho the startup path matches one of the first 2 items. What am I doing wrong?

Dim sPath

sPath = Options.DefaultFilePath(wdStartupPath)

If sPath = "C:\office\startup" Then
Application.Run MacroName:="modMyMenu.ShowFileForm"

ElseIf sPath = "C:\office_2\Startup" Then
Application.Run MacroName:="modMyMenu2.ShowFileForm"

Else
MsgBox "You have not set the Startup path for Word to the proper location. Consult your local systems administrator for assistance." _
, vbOKOnly, "Startup Path Error"

End If
Hi Kev,
You can just modify your existing code to have a couple of extra
variables which can be converted to lowercase for your comparison of the
strings as the actual reading from word may be mixed case. Try the code
below, that should work fine although I have not tested it.

You might want to look at Select Case statements as well.

Dim strStartupPath as string
Dim Menu1 as string
Dim Menu2 as string

strStartupPath = Options.DefaultFilePath(wdStartupPath)
Menu1 = "C:\office\startup"
Menu2 = "C:\office_2\Startup"

If LCase(strStartupPath) = LCase(Menu1) Then
Application.Run MacroName:="modMyMenu.ShowFileForm"
ElseIf LCase(strStartupPath) = LCase(Menu2) Then
Application.Run MacroName:="modMyMenu2.ShowFileForm"

Else
MsgBox "You have not set the Startup path for Word to the
proper location. Consult your local systems administrator for
assistance." _
, vbOKOnly, "Startup Path Error"

End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top