Hallo Bambusmofa!
Also welche VB Version meinst Du denn jetzt? VB6 oder VB.NET?
also für beide Versionen gilt:
- Verweis hinzufügen
- Wähle je nach installierter Office Version aus:
- Microsoft Excel 11 Object Library (oder auch Microsoft Excel 10 Object Library)
dann füge folgenden Code ein:
Imports Microsoft.Office.Interop.Excel
Imports System.Reflection
Imports System.Runtime.InteropServices
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim excelApp As New Microsoft.Office.Interop.Excel.Application()
If (excelApp Is Nothing) Then
MessageBox.Show("EXCEL could not be started. Check that your office installation and project references are correct.")
End If
excelApp.Visible = True
Dim workbooks As Workbooks = excelApp.Workbooks
Dim workbook As _Workbook = workbooks.Add(XlWBATemplate.xlWBATWorksheet)
Dim sheets As Sheets = workbook.Worksheets
Dim worksheet As _Worksheet = CType(sheets.Item(1), _Worksheet)
If (worksheet Is Nothing) Then
MessageBox.Show("Worksheet could not be created. Check that your office installation and project references are correct.")
End If
Dim aRange As Range = worksheet.Range("C1", "C7")
If (aRange Is Nothing) Then
MessageBox.Show("Could not get a range. Check to be sure you have the correct versions of the office DLLs.")
End If
'Fill the cells in the C1 to C7 range of the worksheet with the number 6.
Const nCells As Integer = 6
Dim args1(0) As Object '= New Object(0)
args1(0) = nCells
aRange.Value = args1
End Sub
End Class
cu
Tobi
Antworten
Vorsicht bei der Eingabe: Die Zeichen ' oder -- sind nicht erlaubt!