Cannot create new Excel.Application - vb.net

I have this class in which I want to create a new Excel application to export some data to an Excel workbook, but I can't seem to create the application itself.
I already added the Microsoft.Office.Interop.Excel.dll reference to the Bin folder:
And tried to add the code like this:
Imports Microsoft.VisualBasic
Imports Excel = Microsoft.Office.Interop.Excel
Public Class ExcelExport
Public Sub Export()
Dim excel As New Excel.Application
End Sub
End Class
But when I do I can't find the Application:
Any ideas why it wont work?
VS 2008, VB.NET, .NET 3.5, Office 2007, Windows 7 Ultimate x64

Related

LinqPad 7 - C# - Microsoft.VisualBasic.Interaction.GetObject

Solved by Comment from Joe Albahari
In LinQPad 7 I try to connect to an open Excel Application.
In C# .net this is easy done by eg:
public Microsoft.Office.Interop.Excel.Application ExcelApplication; ExcelApplication = (Application)Microsoft.VisualBasic.Interaction.GetObject(Class: "Excel.Application");
With references to Microsoft.Office.Interop.Excel and Microsoft.VisualBasic
In LinQPad 7 I tried the same but ExcelApplication is null (Yes Excel is open!)
References are set and Namespace imported.
It shows no error, just does not connect.
What am I doing wrong?
(The example from LinqPad for Excel creates a new excel application.
thanks for any help

MsoAutomationSecurity is ambiguous in the namespace of Microsoft.Office.Core

I am trying to use Microsoft.Office.Core.MsoAutomationSecurity in vb.net to set the security mode of an application when opening an excel file. But when I declare this variable on my code in vb.net:
Dim secAutomation As New Microsoft.Office.Core.MsoAutomationSecurity
it has a blue lining below Microsoft.Office.Core.MsoAutomationSecurity and on the Error window, this is listed:
'MsoAutomationSecurity' is ambiguous in the namespace 'Microsoft.Office.Core'
Type 'Microsoft.Office.Core.MsoAutomationSecurity' is not defined.
I hope anyone could help me fix this.
EDITED:
Imports OfficeCore = Microsoft.Office.Core
Imports excelApp = Microsoft.Office.Interop.Excel
Sub ExcelSecurity()
Dim secAutomation As OfficeCore.MsoAutomationSecurity
secAutomation = Microsoft.Office.Core.MsoAutomationSecurity.msoAutomationSecurityLow
End Sub
thank you!
The main problem with this question is that on one (1) solution there are 4 projects. The reference on the other projects has a duplicate Reference when adding the said Reference which is the Microsoft Office 14.0 Object Library. When I see the References on the other projects, the Microsoft Office 14.0 Object Library has a duplicate with different versions, to fix this problem I just removed the outdated version of the Reference.
This error throws due to not add reference for MS Office which installed on your machine. Under project solution > References > Add references > COM > Microsoft office 16.06 Object library marked as checked and saved.
After showing your code minor modification needed as below:
Imports OfficeCore = Microsoft.Office.Core
Imports excelApp = Microsoft.Office.Interop.Excel
Sub ExcelSecurity()
Dim secAutomation As OfficeCore.MsoAutomationSecurity
secAutomation = Microsoft.Office.Core.MsoAutomationSecurity.msoAutomationSecurityLow
End Sub
I hope it will resolve your issue without any other changes. Let me know if any further issues.

Reading and Parsing Excel in .NET

I have googled, and rummaged through stackoverflow with no luck on the matter.
I have found countless ways to import an entire excel file into a datagridview, but this is not what I want.
Basically, I have an excel file with multiple users (in one column) and a unique ID in another column. I want to only parse specific users and the corresponding unique ID from that row.
How Can I do this?
There are several ways to read the contents of an Excel file. One possibility is to use Excel's object model through the Excel Interop API. Using this approach, you'll interact with Excel using objects:
Imports Microsoft.Office.Interop
Public Class ExcelReader
Public Sub Read(filename As String)
Dim excel As New Excel.Application
Dim book As Excel.Workbook = excel.Workbooks.Open(filename)
Dim sheet As Excel.Worksheet = book.Worksheets("Sheet1")
Dim first_cell_text As String = sheet.Cells(1, 1).Value().ToString
Dim a_number As Integer = sheet.Cells(1, 2).value
End Sub
End Class
You need to add a reference to the Excel interop DLL, which on my machine is located at C:\Program Files (x86)\Microsoft Visual Studio 9.0\Visual Studio Tools for Office\PIA\Office12\Microsoft.Office.Interop.Excel.dll. I am pretty sure you need to have Excel installed on any machine that runs the app, too.
Documentation for the Excel object model is available here.
Other options include reading an Excel file as if it were a database using ADO.NET, and using third party libraries that can read Excel.

vb.net windows form connection excelworkbook

I'm creating a vb.net excellworkbook.xlsx file and worksheet from windowsform want to achieve. I could not. I do not make a connection between vb.net and windowsform. I need to use in my project, but dozens excelworkbook excelworkbook excel in the program I need to do without opening the windows forms and links to all the relevant supposed to do. I would be glad if you can help.
Frankly, I have almost no clue what you're asking. Almost no clue anyway.
Access, read and write an excel workbook in Visual Studio vb.net by doing the following:
Click Project > Add Reference > COM > Microsoft Excel Object Library
In your code you will need:
Imports Microsoft.Office.Interop
Then you can create the excel object:
Dim ExcelAp As New Excel.Application
Open a workbook:
Dim WrkBk As Excel.Workbook = ExcelAp.Workbooks.Open("Path")
And then access cells and their values:
WrkBk.Cells(1, 1).value = "Hello World!"
That might give you a start anyway.

Visual Basic 2010 Express - How to use excel function in Visual Basic 2010 Express

I want to use excel function in Visual Basic 2010 Express. I tried to search in the internet to see how to do that.
I come across with this solution:
Module Module1
Sub Main()
Imports Excel = Microsoft.Office.Interop.Excel
Dim oXLApp As New Excel.Application
Dim ExcelMath As Excel.WorksheetFunction
ExcelMath = New Excel.WorksheetFunction
Dim I As Double
Dim s As Double
I = ExcelMath.Average(1, 2, 3, 4, 5)
s = ExcelMath.StDev(1, 2, 3, 4, 5)
ExcelMath = Nothing
oXLApp.Quit()
oXLApp = Nothing
End Sub
End Module
However, there is error of:
1. Syntax error.
2. Type 'Excel.Applciation" is not defined.
3. Type 'Excel.WorksheetFunction' is not defined.
How should it be resolved?
Or is there other simple way to do that?
Thanks a lot!
Not sure if it has to do with using the Express edition or not, but I had the same problem.
Whenever I attempted to use Imports Microsoft.Office.Interop.Excel it would not work.
I went to Project > Add References > COM > Microsoft Office14.0 Object Library and it works now.
My guess is that you need to add a reference to the Microsoft Excel Object Library. For a brief tutorial, see http://support.microsoft.com/kb/301982 (more specifically, step #3).
If this doesn't resolve the problem, let us know.
Include an import statement at the top : Imports Microsoft.Office.Interop.Excel