Solved

Visual Studio Tools for office 2005 application object

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

734 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