Public Sub TestMitVerweis_Click()
Dim objExcel As Excel.Application
Dim objExcelWorkbook As Excel.Workbook
Dim objExcelSheet As Excel.Worksheet
Dim strExcelFullName As String
Dim strExcelFile As String
Dim strExcelPath As String
Dim blnCreated As Boolean
strExcelPath = "E:\Temp"
strExcelFile = "Test.xls"
strExcelFullName = strExcelPath & "\" & strExcelFile
blnCreated = False
'neues Excel-Objekt erstellen
Set objExcel = New Excel.Application
'prüfen ob File existiert
If Fileexists(strExcelFullName) = True Then
'Instanz auf bestehendes Dokument referenzieren
Set objExcelWorkbook = objExcel.Workbooks.Open(strExcelFullName)
Else
'neues workbook hinzufügen
Set objExcelWorkbook = objExcel.Workbooks.Add
blnCreated = True
End If
'erste Seite im Workbook aufrufen
Set objExcelSheet = objExcelWorkbook.Worksheets(1)
' Generiert oder nicht...
If blnCreated Then
objExcelWorkbook.SaveAs strExcelFullName
objExcelWorkbook.Close False
Else
objExcelWorkbook.Close True
End If
Set objExcelSheet = Nothing
Set objExcelWorkbook = Nothing
'Schliessen...
objExcel.Quit
'Aufräumen...
Set objExcel = Nothing
End Sub