Hallo,
ich erstelle ein Excel-Workbook. Darin schreibe ich in 2 Blätter. Nun möchte ich auch eine Formel eintragen, die sich auf Werte des anderen Blattes bezieht. Daran scheitere ich derzeit mit der Fehlermeldung: Ausnahme von HRESULT: 0x800A03EC
Die Formel die ich eintragen möchte ist die:
xlBlattP.Range("E" & Zp - 1).FormulaR1C1 = "=Massen!R[" & Zl - 2 - Zp & _
"]C[19]" Der Code zum erstellen der Datei ist:
Public Function erstelle_Xl_WB_Massen(ByVal SPath As String, ByVal Filename As _
String) As Boolean
Dim xlApp As Microsoft.Office.Interop.Excel.Application
Dim xlMappe As Microsoft.Office.Interop.Excel.Workbook = Nothing
Dim xlBlattM As Microsoft.Office.Interop.Excel.Worksheet = Nothing
Dim xlBlattP As Microsoft.Office.Interop.Excel.Worksheet = Nothing
Dim Zl As Integer = 1, Zp As Integer = 1
xlApp = New Microsoft.Office.Interop.Excel.Application
xlMappe = xlApp.Workbooks.Add ' New
' Microsoft.Office.Interop.Excel.Workbook
xlBlattP = xlMappe.Worksheets(1) 'xlMappe.Worksheets.Add
xlBlattP.Name = "Kurztext"
xlBlattM = xlMappe.Worksheets(2) 'xlMappe.Worksheets.Add
xlBlattM.Name = "Massen"
Dim ColArr() As String ' Array für die
' Spaltenbreiten (22)
ReDim ColArr(8)
Call Fill_WSk_ColArr(ColArr) ' definiert die
' Spaltenbreiten des WSk
If XL_WsP_Header(xlBlattP, ColArr, Zp) = False Then GoTo Fehler
ReDim ColArr(22)
Call Fill_WSm_ColArr(ColArr) ' definiert die
' Spaltenbreiten des WSm
If XL_WsM_Header(xlBlattM, ColArr, Zl) = False Then GoTo Fehler ' Header
For i As Integer = 0 To UBound(vntGAEB, 1)
If vntGAEB(i, 0) = "POSITION" Then
Dim OZex As String = vntGAEB(i, 1) '
' OZ-Nummer aus der Position
Dim KTex As String = vntGAEB(i, 7) '
' Kurztext zur Position
Dim Einh As String = vntGAEB(i, 4) '
' Einheit zur Position
Dim EP As String = vntGAEB(i, 5) '
' Einheit zur Position
Dim BeginnPos As Integer = 2
Dim OZView As DataView = New DataView(DirectCast( _
Hauptform.BsMassen.DataSource, DataTable), "OZ = '" & OZex & _
"'", "Adresse ASC", DataViewRowState.CurrentRows)
If OZView.Count > 0 Then _
' Wenn es Daten zur OZ gibt
' Datenzeilen der OZ
Dim MassenBeginn As Integer = Zl
If Xl_WsM_Add_RowOZ(xlBlattM, OZex, KTex, Zl) = False Then _
GoTo Fehler ' Beginn Positione
BeginnPos = Zl _
' zum späteren Summieren
For Each ViewRow As DataRowView In OZView _
' jeden Datensatz zur OZ
If Xl_WsM_Add_RowData(xlBlattM, ViewRow, Einh, Zl) = _
False Then GoTo Fehler ' Datenzeile
Next
If XL_WsM_Add_RowSumm(xlBlattM, OZex, BeginnPos, Zl) = _
False Then GoTo Fehler ' Summenzeile
Dim ZlDiff As Integer = Zl - 2 - Zp
Dim ColDiff As Integer = 19
xlBlattP.Range("E" & Zp - 1).FormulaR1C1 = "=Massen!R[" & _
Zl - 2 - Zp & "]C[19]"
xlBlattP.Range("E" & Zp - 1).Formula = "=Massen!S" & Zl - 2 _
& " ' Formel auf Ergebnis setzen"
End If
Else
Debug.Print(vntGAEB(i, 0))
Select Case vntGAEB(i, 0)
Case "GRP"
If XL_WsP_Add_RowOZ(xlBlattP, i, Zp) = False Then GoTo _
Fehler
End Select
End If
Next
Try
xlMappe.SaveAs(SPath & "\" & Filename & ".xls")
Catch ex As Exception
GoTo Fehler
End Try
xlBlattP = Nothing
xlBlattM = Nothing
xlMappe = Nothing
xlApp = Nothing
Return True
Fehler:
xlBlattP = Nothing
xlBlattM = Nothing
xlMappe = Nothing
xlApp = Nothing
Return False
End Function Kann ich bei der noch nicht gespeicherten Mappe nicht blattübergreifend arbeiten?
Danke für die Hilfe
Gruß Christian |