Hallo,
ich habe folgenden Code, der aus Outlook Excel startet und leider bleibt bei mir immer das Excel Programm im TaskManager stehen. Wenn ich Outlook schliesse, schliesst sich auch Excel. Aber ich möchte, dass sich Excel nach der Prozedur beendet, so wie ich es eigentlich im Code schreibe.
'Open Excel in case it is not yet open
If excApp Is Nothing Then
Set excApp = CreateObject("Excel.Application")
excStart = True
End If
'Get date from cell A2 in workbook1
Set excWkb = excApp.Workbooks.Open(FILE_PATH_TMP & "~tmp_" & olAtt.FileName)
str = excWkb.ActiveSheet.Cells(2, 1)
year = Right(str, 4)
str = Right(str, 4) & "-" & Mid(str, 4, 2) & "-" & Left(str, 2)
'Clear workbook2
Set excWkb2 = excApp.Workbooks.Open(FILE_IMPORT)
With excWkb2.ActiveSheet
.Range("A2").Select
.Range(Selection, Selection.End(xlDown)).Select
.Range(Selection, Selection.End(xlToRight)).Select
excWkb2.Application.Selection.ClearContents
.Range("A2").Select
excWkb2.Application.CutCopyMode = False
End With
'Copy content from workbook1 to workbook2
excWkb.Activate
With excWkb.ActiveSheet
.Range("A2").Select
.Range(Selection, Selection.End(xlDown)).Select
.Range(Selection, Selection.End(xlToRight)).Select
excWkb.Application.Selection.Copy
.Range("A2").Select
excWkb2.Activate
'excWkb2.Application.ActiveCell.PasteSpecial
'excWbk2.ActiveSheet.Range("A2").Select
excWkb2.Application.ActiveSheet.Paste
excWkb2.Save
excWkb.Application.CutCopyMode = False
End With
'Closing
excWkb.Close False
excWkb2.Close False
If excStart = True Then excApp.Quit
Set excWkb = Nothing
Set excWkb2 = Nothing
Set excApp = Nothing
Vielen Dank
|