JORDJB999
06-05-2008, 09:43 AM
Hi i have a problem, with this code. Its part of some code used in outlook to open an attachment in excel run a macro save and close. But it runs fine first time then wont work a second time untill i close outlook and ecxel down manually. Wen i watched the Task manager as it ran, the first instance of the excel.exe process doesnt disapear then i second excel.exe starts if it runs again. I think this maybe my problem, but im a total noooooob, so any help much apreciated. im using 2007.
Sub PrintAtt(file As String)
Dim xlApp As Object
Dim wb As Object
'in the background, create an instance of xl then open, print, quit
Set xlApp = CreateObject("Excel.Application")
On Error Resume Next
xlApp.Workbooks.Open ("C:\Program Files\Microsoft Office\Office12\XLSTART\opips.XLSM")
On Error GoTo 0
xlApp.Workbooks.Open (file)
xlApp.Run ("opips.XLSM!stat2")
ActiveWorkbook.Save
ActiveWorkbook.Close savechanges:=False
xlApp.Quit
'tidy up
Set wb = Nothing
Set xlApp = Nothing
End Sub
Sub PrintAtt(file As String)
Dim xlApp As Object
Dim wb As Object
'in the background, create an instance of xl then open, print, quit
Set xlApp = CreateObject("Excel.Application")
On Error Resume Next
xlApp.Workbooks.Open ("C:\Program Files\Microsoft Office\Office12\XLSTART\opips.XLSM")
On Error GoTo 0
xlApp.Workbooks.Open (file)
xlApp.Run ("opips.XLSM!stat2")
ActiveWorkbook.Save
ActiveWorkbook.Close savechanges:=False
xlApp.Quit
'tidy up
Set wb = Nothing
Set xlApp = Nothing
End Sub