Problem calling Excel and ending the call

  • Thread starter Thread starter Keith
  • Start date Start date
K

Keith

Hello,

I don't know if this is the correct forum to ask this
question, but since it involves Powerpoint, I'm thinking
that maybe someone here will know the answer.
I have a program that creates an Excel object, opens an
Excel file and imports data into my powerpoint
presentation. The problem is that once the process is
done, Windows thinks that the Excel workbook is locked for
use by another user, and won't allow me to open the Excel
workbook in Excel.

I believe this code should be adequately closing the Excel
sheet, but apparently I'm wrong. Any suggestions on what
I can do to close Excel better?

' the following snippet of code was edited for this
question, using MS Word I hope
' it maintains correct formatting when pasted into the
forum message.

Str2Excel = "C:\temp.xls"
Dim ExcelApp As New Excel.Application
Dim ExcelWorkbook As Excel.Workbook
Dim ExcelSheet As Excel.Worksheet
ExcelApp.Visible = True
Set ExcelWorkbook = ExcelApp.Workbooks.Open(str2Excel)
Set ExcelSheet = ExcelWorkbook.Worksheets("Sheet1")
ExcelSheet.Activate


Other code goes here

Excel related code ends with.

ExcelApp.Visible = False 'make the excel app invisible
again
Set ExcelSheet = Nothing
Set ExcelWorkbook = Nothing
Set ExcelApp = Nothing


Thanks

Keith
 
Str2Excel = "C:\temp.xls"
Dim ExcelApp As New Excel.Application
Dim ExcelWorkbook As Excel.Workbook
Dim ExcelSheet As Excel.Worksheet
ExcelApp.Visible = True
Set ExcelWorkbook = ExcelApp.Workbooks.Open(str2Excel)
Set ExcelSheet = ExcelWorkbook.Worksheets("Sheet1")
ExcelSheet.Activate


Other code goes here

Excel related code ends with.

ExcelApp.Visible = False 'make the excel app invisible
again

' Add this:
ExcelApp.Quit
Set ExcelSheet = Nothing
Set ExcelWorkbook = Nothing
Set ExcelApp = Nothing

Thanks

Keith

I'd comment out the "Thanks" and "Keith" lines, as they'll likely throw
errors. That and the .Quit method should do it, I expect. <g>
 
Back
Top