Solved

Visual Studio Tools for office 2005 application object

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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

679 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