msvisual.com Forum Index
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Best way to determine installed version of MS Office

 
Post new topic   Reply to topic    msvisual.com Forum Index -> VB Syntax
Author Message
GeorgeAtkins



Joined: 04 Oct 2007
Posts: 5

PostPosted: Wed Jun 27, 2007 11:52 am    Post subject: Best way to determine installed version of MS Office Reply with quote

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

Thanks for any advise!
George Atkins

Archived from group: microsoft>public>vb>syntax
Back to top
View user's profile Send private message
MikeD



Joined: 04 Oct 2007
Posts: 3348

PostPosted: Wed Jun 27, 2007 3:11 pm    Post subject: Re: Best way to determine installed version of MS Office Reply with quote

"GeorgeAtkins" wrote in message @microsoft.com...
> 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
Back to top
View user's profile Send private message
GeorgeAtkins



Joined: 04 Oct 2007
Posts: 5

PostPosted: Wed Jun 27, 2007 12:26 pm    Post subject: Re: Best way to determine installed version of MS Office Reply with quote

Thank you, Mike. I did re-post in a better forum. And I'll look into your
suggestions, too. Appreciate the good tips. Have a nice day!
George

"MikeD" wrote:

>
> "GeorgeAtkins" wrote in message
> @microsoft.com...
> > 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
>
>
>
Back to top
View user's profile Send private message
Bob Butler



Joined: 04 Oct 2007
Posts: 1081

PostPosted: Wed Jun 27, 2007 12:36 pm    Post subject: Re: Best way to determine installed version of MS Office Reply with quote

"GeorgeAtkins" wrote in message @microsoft.com...
> Thank you, Mike. I did re-post in a better forum.

More appropriate forum, maybe... hardly "better"
Back to top
View user's profile Send private message
Karl E. Peterson



Joined: 04 Oct 2007
Posts: 4836

PostPosted: Wed Jun 27, 2007 2:15 pm    Post subject: Re: Best way to determine installed version of MS Office Reply with quote

GeorgeAtkins wrote:
> 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?

Use ShellExecute, and let Windows take over the worry. (If you really want to know
the installed Office version, you can query the App.Version property exposed by the
Word, Excel, and/or PowerPoint object models. Which raises another point -- if
you're working with Office, dump that silly flamework and use a *real* COM-based
language. )
--
..NET: It's About Trust!
http://vfred.mvps.org

Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    msvisual.com Forum Index -> VB Syntax All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group