Solved

Visual Studio Tools for office 2005 application object

Posted on 2007-11-20
1
146 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:Murray Brown
[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
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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

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 article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

626 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