How do I check for existence of Powerpoint and Excel from VB app

I have a vb .net application that creates powerpoint and excel presentations.  I works fine, unless the user doesn't have powerpoint and excel installed on their computers.  How do I check for that so that I can issue a warning to the user?

Thanks!
spmcmorrowAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
wguerramConnect With a Mentor Commented:
Try this:

If you get an error it means the activeX does not exist:        

        Dim x As Object
        Try
            x = CreateObject("PowerPoint.Application")
        Catch ex As Exception
            MsgBox(ex.Message)
        Finally
            x = Nothing
        End Try

0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
One way would be to check the listing of programs that appear in the "Add/Remove Programs" listing you see in the control panel.  This is done by enumerating the "Software\Microsoft\Windows\CurrentVersion\Uninstall" key under the LocalMachine area.  The "DisplayName" value is the installed application.

On my system there is only one entry for the whole office suite, "Microsoft Office XP Professional".  I'm not sure how it looks for other versions of Office.

Below is an application that populates a ListBox with all installed applications on the system.  I'm not sure if Administrator rights are required to use this approach.

Regards,

Idle_Mind

Imports Microsoft.Win32

Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents ListBox1 As System.Windows.Forms.ListBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.ListBox1 = New System.Windows.Forms.ListBox
        Me.SuspendLayout()
        '
        'ListBox1
        '
        Me.ListBox1.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                    Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.ListBox1.Location = New System.Drawing.Point(8, 8)
        Me.ListBox1.Name = "ListBox1"
        Me.ListBox1.Size = New System.Drawing.Size(288, 160)
        Me.ListBox1.TabIndex = 0
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(304, 182)
        Me.Controls.Add(Me.ListBox1)
        Me.Name = "Form1"
        Me.Text = "Add/Remove Program Listing"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            Dim rk As RegistryKey = Registry.LocalMachine.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Uninstall")
            Dim sk As String
            Dim appKey As RegistryKey
            Dim displayNameValue As Object
            Dim displayName As String
            ListBox1.Sorted = True
            ListBox1.BeginUpdate()
            If Not (rk Is Nothing) Then
                For Each sk In rk.GetSubKeyNames
                    appKey = rk.OpenSubKey(sk)
                    displayNameValue = appKey.GetValue("DisplayName")
                    If Not (displayNameValue Is Nothing) Then
                        ListBox1.Items.Add(CType(displayNameValue, String))
                    End If
                Next
            End If
            ListBox1.EndUpdate()
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Information, "Error Accessing Registry")
        End Try
    End Sub

End Class
0
 
wguerramCommented:
The same for excel

 Dim x As Object
        Try
            x = CreateObject("Excel.Application")
        Catch ex As Exception
            MsgBox(ex.Message)
        Finally
            x = Nothing
        End Try
0
Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

 
Bob LearnedCommented:
I like the solution that wguerram has shown, since registry keys are different depending on what version of Excel and PowerPoint that the user has installed.  Generic solutions are the best.

Bob
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
I agree...wguerram's method will be much cleaner.  This is why I usually preface my posts with "One way would be to..." instead of "The best way would be to..."

=)
Idle_Mind
0
 
Bob LearnedCommented:
That's true, but the "one way" could be the "best way" for you *GRIN*.  It's all in the eye of the beholder.

Bob
0
 
spmcmorrowAuthor Commented:
Should I install active x with my application, or just put out an error message to the user.
0
 
Bob LearnedCommented:
It is against Micro$oft's license agreement to install it if they don't have the application installed.  Therefore, you should put up an error message.

Bob
0
All Courses

From novice to tech pro — start learning today.