Re: Best way to determine installed version of MS Office
- From: "MikeD" <nobody@xxxxxxxxxxx>
- Date: Wed, 27 Jun 2007 11:11:14 -0400
"GeorgeAtkins" <GeorgeAtkins@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:3ABFC995-8926-4A6A-A949-CFD1A0F44257@xxxxxxxxxxxxxxxx
Greetings,
I wrote a small Exe that simply runs Shell to load PowerPoint and launch a
particular file, depending on the day of the week. However, it was set up
for
office 2003 (hardcoded path). I now want to have the program run the Shell
for either Office 11 or Office 12, depending upon which version is
installed
on a desktop. What is the most efficient way to code this?
My code is as follows:
Sub main()
Try
Dim ps1 As New PermissionSet(PermissionState.Unrestricted)
ps1.Demand()
Dim MyDate As Date
Dim DayOfWeek As Integer
MyDate = Today
DayOfWeek = Weekday(MyDate)
' Launch the powerpoint file for the current day of the week.
Select Case DayOfWeek
Case 1
Shell("""C:\Program Files\Microsoft
Office\OFFICE11\powerpnt.exe"" /s " & Chr(34) + CurDir() &
"\Sunday.ppt""")
Case 2
Shell("""C:\Program Files\Microsoft
Office\OFFICE11\powerpnt.exe"" /s " & Chr(34) + CurDir() &
"\Monday.ppt""")
Case 3
Shell("""C:\Program Files\Microsoft
Office\OFFICE11\powerpnt.exe"" /s " & Chr(34) + CurDir() &
"\Tuesday.ppt""")
Case 4
Shell("""C:\Program Files\Microsoft
Office\OFFICE11\powerpnt.exe"" /s " & Chr(34) + CurDir() &
"\Wednesday.ppt""")
Case 5
Shell("""C:\Program Files\Microsoft
Office\OFFICE11\powerpnt.exe"" /s " & Chr(34) + CurDir() &
"\Thursday.ppt""")
Case 6
Shell("""C:\Program Files\Microsoft
Office\OFFICE11\powerpnt.exe"" /s " & Chr(34) + CurDir() &
"\Friday.ppt""")
Case 7
Shell("""C:\Program Files\Microsoft
Office\OFFICE11\powerpnt.exe"" /s " & Chr(34) + CurDir() &
"\Saturday.ppt""")
End Select
Catch e As SecurityException
MsgBox(e.Message)
End Try
End
End Sub
Don't use Shell and NEVER hard-code paths. If a user doesn't install Office
(or PowerPoint) to the default installation folder, your code is never going
to work. Use Automation or the FindExectuable Win32API function (or I
suppose you could shell using the ShellExecute API function).
However, since your using VB.NET (the Try..Catch gives it away), you're
posting to the wrong newsgroup. This one's for VB6 and under. You want to
post to one with "dotnet" or "vsnet" in the name.
--
Mike
Microsoft MVP Visual Basic
.
- Follow-Ups:
- Re: Best way to determine installed version of MS Office
- From: GeorgeAtkins
- Re: Best way to determine installed version of MS Office
- References:
- Best way to determine installed version of MS Office
- From: GeorgeAtkins
- Best way to determine installed version of MS Office
- Prev by Date: Best way to determine installed version of MS Office
- Next by Date: Re: Best way to determine installed version of MS Office
- Previous by thread: Best way to determine installed version of MS Office
- Next by thread: Re: Best way to determine installed version of MS Office
- Index(es):
Relevant Pages
|