determining current version of PowerPoint

G

Guest

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 (I naively hardcoded the path) and I also used Shell. Does
anybody have a snipped showing a more efficient method for launching a
Powerpoint file, regardless of which version of Office is running?

My current, ineffecient code:
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
 
N

Newbie Coder

George,

Here's a way to do it:

Imports Microsoft.Win32
Imports System.Diagnostics.Process

#Region "Get PowerPoint Path"

Private Function GetPowerPointPath() As String
Dim reg As RegistryKey
Try
reg =
Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\App
Paths\powerpnt.exe", False)
Dim strShortPath As String = reg.GetValue("", "")
reg.Close()
Return strShortPath
Catch ex As Exception
' Some error handling here
End Try
End Function

#End Region

#Region "Get Day Of Week"

Private Function GetDayOfWeek() As String
Dim dt As DateTime = DateTime.Today
Return dt.DayOfWeek.ToString
End Function

#End Region

#Region "Run PowerPoint Presentation"

Private Sub RunPowerPointPresentation()
Dim strPPT As String = "C:\PPTs" & "\" & GetDayOfWeek() & ".ppt"
Dim psi As New ProcessStartInfo(GetPowerPointPath())
Try
With psi
.Arguments = "/s " & strPPT
.WindowStyle = ProcessWindowStyle.Maximized
End With
Process.Start(psi)
Catch ex As Exception
' Error Handling Here
End Try
End Sub

I have chosen 'C:\PPTs' as the path I stored the PowerPoint files in

Hope this helps,
 
G

Guest

Sorry that I missed your post; I forgot to mark the Notify box and work has
kept me busy. I'll try this out when I get back to work, first thing. Thanks
a whole lot for the solution.
george atkins
 
G

Guest

Thanks for the code. When I tried to run it, I received the following
"warning" that prevents the code from running or compiling:

"Warning 1 Function 'GetPowerPointPath' doesn't return a value on all code
paths. A null reference exception could occur at run time when the result is
used."

I'm running a standard installation of PowerPoint 2007 on an XP SP2 machine.
Do you have any troubleshooting advise? I checked for the path in the
Registry and it is correct.

George
 
G

Guest

Well, I think I may have an inkling of the problem.
The function that determines the PPT path, returns the following string:
"C:\PROGRA~1\MICROS~2\Office12\POWERPNT.EXE"

Why Microsoft records these old-fashioned, truncated names is beyond me. But
I believe the ~1 and ~2 syntax is what is causing the problem. I could edit
the syntax, but as I'm going to run this on other machines, this is not a
good solution.

I revised the code to show: reg.GetValue("Path", ""). This returns a valid,
full path, but the code continues to fail with the warning previously
reported.

Any other ideas?
George
 
N

Newbie Coder

George,

In my original code I wrote:

GetValue("", "")

This gets the default value & if doesn't exist returns "". You can change the
second "" to the default path to MS Powerpoint, which will stop the error
 
N

Newbie Coder

George,

' Import
Imports System.IO

To get the Long Path Name use this function:

Public Shared Function GetLongPath(ByVal path As String) As String
Dim root As String = System.IO.Path.GetPathRoot(path)
Dim folders As String() = path.Substring(root.Length). _
Split(System.IO.Path.DirectorySeparatorChar)
Dim res As String = root
Dim name As String
For Each name In folders
Dim di = New DirectoryInfo(res)
Dim fsi As System.IO.FileSystemInfo() = _
di.GetFileSystemInfos(name)
If fsi.Length = 1 Then
res = fsi(0).FullName
Else
' Error handling here
End If
Next
Return res
End Function

The above isn't my function but it works fine
 

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