Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Help with checking if excel exist in client's computer

Posted on 2016-10-15
9
Medium Priority
?
66 Views
Last Modified: 2016-11-25
Hi.

How do you find out if excel exist and which version of excel is on a client's computer using VB.NET?

Thanks,

Victor
0
Comment
Question by:vcharles
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 53

Expert Comment

by:Rgonzo1971
ID: 41844718
HI,

You could read the registry

HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\excel.exe
and read the path


Regards
0
 

Author Comment

by:vcharles
ID: 41844728
Can you please send me the complete code as it would be in the vb.net apllication. Thanks.
0
 
LVL 53

Expert Comment

by:Rgonzo1971
ID: 41844729
try something like this

Dim readValue = My.Computer.Registry.GetValue(
    "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\excel.exe", "Path", Nothing)
MsgBox("The value is " & readValue)
0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 

Author Comment

by:vcharles
ID: 41844733
Hi,

I received the following error message:

Registry key name must start with a valid base key name.

Victor
0
 
LVL 53

Expert Comment

by:Rgonzo1971
ID: 41844736
then try

Dim readValue = My.Computer.Registry.GetValue(
     "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\excel.exe", "Path", Nothing)
 MsgBox("The value is " & readValue)
0
 

Author Comment

by:vcharles
ID: 41844747
Hi,

The message box shows readValue is empty, but I do have excel on my PC.

Victor
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 41844974
0
 
LVL 53

Expert Comment

by:Rgonzo1971
ID: 41846162
Has your code

Imports Microsoft.Win32

 to read the registry
Dim readValue As String = _
            Registry.GetValue( "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\excel.exe", "Path", "")
Console.WriteLine( readValue )

Open in new window

0
 
LVL 34

Accepted Solution

by:
it_saige earned 2000 total points
ID: 41846681
Another couple of methods (although one could potentially be what is used and recommended by Eric):
Imports Microsoft.Office.Interop
Imports Microsoft.Win32

Module Module1
	Sub Main()
		Console.Write("Detect using COM object - ")
		DetectFromCOMObject()
		Console.Write("Detect using Registry - ")
		DetectFromRegistry()
		Console.ReadLine()
	End Sub

	Private Sub DetectFromCOMObject()
		Dim objEApp As Excel.Application = Nothing
		Try
			objEApp = DirectCast(CreateObject("Excel.Application"), Excel.Application)
			Select Case objEApp.Version
				Case "7.0"
					Console.WriteLine("Excel 95")
				Case "8.0"
					Console.WriteLine("Excel 97")
				Case "9.0"
					Console.WriteLine("Excel 2000")
				Case "10.0"
					Console.WriteLine("Excel 2002")
				Case "11.0"
					Console.WriteLine("Excel 2003")
				Case "12.0"
					Console.WriteLine("Excel 2007")
				Case "14.0"
					Console.WriteLine("Excel 2010")
				Case "15.0"
					Console.WriteLine("Excel 2013")
				Case "16.0"
					Console.WriteLine("Excel 2016")
				Case Else
					Console.WriteLine("Undocumented Version - {0}", objEApp.Version)
			End Select
		Catch ex As Exception
			Console.WriteLine("Excel is not installed or an instance cannot be created")
		Finally
			If objEApp IsNot Nothing Then objEApp.Quit()
			objEApp = Nothing
		End Try
	End Sub

	Private Sub DetectFromRegistry()
		Using key As RegistryKey = Registry.ClassesRoot.OpenSubKey("\Excel.Application\CurVer", False)
			If key IsNot Nothing Then
				Dim value As String = key.GetValue(String.Empty)
				value = value.Substring(value.LastIndexOf(".") + 1)
				Select Case value
					Case "7"
						Console.WriteLine("Excel 95")
					Case "8"
						Console.WriteLine("Excel 97")
					Case "9"
						Console.WriteLine("Excel 2000")
					Case "10"
						Console.WriteLine("Excel 2002")
					Case "11"
						Console.WriteLine("Excel 2003")
					Case "12"
						Console.WriteLine("Excel 2007")
					Case "14"
						Console.WriteLine("Excel 2010")
					Case "15"
						Console.WriteLine("Excel 2013")
					Case "16"
						Console.WriteLine("Excel 2016")
					Case Else
						Console.WriteLine("Undocumented Version - {0}", value)
				End Select
			End If
		End Using
	End Sub
End Module

Open in new window

Produces the following output -Capture.JPGFor the COM object method, don't forget to add a reference to the Microsoft Excel Object Library.  You will want to ensure that you add a reference for the oldest version that you want to support and then set the Embed Interop Types property for the reference to True (http://www.claudiobernasconi.ch/2014/02/13/painless-office-interop-using-visual-c-sharp/).  COM object support is more restrictive as you are limited based upon the oldest PIA that can be found (I believe XP/2002 is the oldest supported but I could be wrong).

-saige-
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question