Solved

Visual Studio Tools for office 2005 application object

Posted on 2007-11-20
1
140 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
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
 
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

810 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