Solved

Visual Studio Tools for office 2005 application object

Posted on 2007-11-20
1
138 Views
Last Modified: 2013-11-26
Hi
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
0
Comment
Question by:murbro
1 Comment
 
LVL 48

Accepted Solution

by:
jpaulino earned 500 total points
Comment Utility
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
 

Try
 

  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)
 

Finally

  objExcelSheet = Nothing

  objExcelApplication = Nothing

  GC.Collect()

End Try

Open in new window

0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

763 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

8 Experts available now in Live!

Get 1:1 Help Now