Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / COM / July 2003



Tip: Looking for answers? Try searching our database.

Excel COM

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Steven Pu - 09 Jul 2003 16:59 GMT
Hey guys,

I got a question about Excel COM.

I'm using it to import data from Excel, so it requires that I start, in the
background, instances of the application itself.

Dim app As New Excel.Application

app.Workbooks.Open(iPath)
app.Workbooks(1).Worksheets(2).Copy()
app.DisplayAlerts = False
app.ActiveWorkbook.SaveAs(oPath,
FileFormat:=Excel.XlFileFormat.xlTextWindows)
app.Workbooks(1).Close(False)
app.Quit()

Do
   If System.Runtime.InteropServices.Marshal.ReleaseComObject(app) = 0 Then
Exit Do
Loop

So after all this, I still see the Excel application residing in memory.
They will exit after I close down the VB program, sometimes. This is a
serious problem - can anyone tell me how I can reliably shut down the
application entirely after I  use them? Thanks.

Steven
Woody - 30 Jul 2003 06:28 GMT
'used to generate the document check list for the applicants
Dim exlApp             As Excel.Application
Dim exlBook            As Excel.Workbook
dim newdocname         as string
'----------------------------------------------------------
' Get Excel if it's running
Set exlApp = GetObject(, "Excel.Application")
If Err <> 0 Then
   'Excel wasn't running, start it from code
   Set exlApp = CreateObject("Excel.Application")
   End If
 
  ' remove old filem create new excel spreadsheet
   Kill App.Path & "/" & newDocName & ".xls"
   
   Set exlBook = Workbooks.Add
   With exlBook
       .Title = newDocName
       .Subject = "compute this"
       .SaveAs FileName:=App.Path & "/" & newDocName & ".xls"
   End With
' make it active
   Workbooks(newDocName & ".xls").Activate
' only need first sheet so activate it and hide the other 2
   With ActiveWorkbook
        Sheets(3).Visible = False
        Sheets(2).Visible = False
        Sheets(1).Activate
   End With
     
 With ActiveSheet
      .PageSetup.LeftHeader = "&D"
      .PageSetup.CenterHeader = "&B" & newDocName
      .PageSetup.RightHeader = "data Header"
     
      .PageSetup.LeftFooter = "&P of &N"
      .PageSetup.CenterFooter = "American Jobs LLC"
      .PageSetup.RightFooter = "&B Company Confidential Information"
     
      .PageSetup.Orientation = xlLandscape
     
 End With
' save spreadsheet, close it, end Excel
 exlBook.Save
 exlBook.Close
 exlApp.Quit
'release excel resources
 Set exlBook = Nothing
 Set exlApp = Nothing
 
this works for me but that isnt a garauntee it will for you.

Woody
I am not responsible for anything you may see with my name attached to
it, i think.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.