Visual Studio Tools for office 2005 application object

Posted on 2007-11-20
Last Modified: 2013-11-26
I have declared the Excel application object as
 Public xlApp As New Microsoft.Office.Interop.Excel.Application()
When I open my main form I want a new instance of Excel to be opened
with an active workbook assigned to this object
Question by:murbro
1 Comment
LVL 48

Accepted Solution

jpaulino earned 500 total points
ID: 20318407
This is using the Excel.Application from Microsoft Excel 11.0 but you only have to change it to Microsoft.Office.Interop.Excel.Application.

Try this:
Dim objExcelApplication As New Excel.Application

Dim objExcelSheet As New Excel.Worksheet

Dim objExcelBook As Excel.Workbook


  If objExcelApplication Is Nothing Then

        MsgBox("Not possible to open Microsoft Excel", MsgBoxStyle.Critical, strMessageTitle)

        Exit Sub

  End If

  Dim oldCI As System.Globalization.CultureInfo = System.Threading.Thread.CurrentThread.CurrentCulture

  System.Threading.Thread.CurrentThread.CurrentCulture = New System.Globalization.CultureInfo("en-US")

  objExcelBook = objExcelApplication.Workbooks.Add

  objExcelSheet = objExcelBook.Worksheets(1)

   objExcelSheet.Cells(1, 1) = "test"  

   objExcelApplication.Visible = True

   System.Threading.Thread.CurrentThread.CurrentCulture = oldCI

Catch COMEx As System.Runtime.InteropServices.COMException

  MsgBox("Error in Microsoft Excel", MsgBoxStyle.Critical, strMessageTitle)

Catch ex As Exception

  MsgBox(ex.Message, MsgBoxStyle.Critical, strMessageTitle)


  objExcelSheet = Nothing

  objExcelApplication = Nothing


End Try

Open in new window


Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
No row return after calling the fillschema method 4 40
C# GridRow get Old/New Value 1 55 mvc input file 2 32
Please explain "Multi-Tenant Services" 5 63
The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

911 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now