Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Visual Studio Tools for office 2005 application object

Posted on 2007-11-20
1
Medium Priority
?
149 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 2000 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

Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

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

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

719 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