|
Hi Raaz, Why using VB6 if you can VB2008 Express Edition free of Microsoft. Oke, that does not answer the question.
First you have to My Progject, right mouse button, Properties. Go to tab References and scroll down, if nessary. Check Excel. The result is Imported Namespaces: Excel. Save the properties.
Oke, the code. First for VB 2008 and VB.NET Public Sub ExcelConnection(ByVal strBestand As String) variables Dim Xcel as Excel.Application Dim XcelBook as Excel.Workbook Dim XcelSheet as Excel.Worksheet
program On Error Resume Next Xcel = CType(GetObject(, "Excel.Application"), Excel.Application) If Err.Number = 0 Then 'Excel is actief Err.Clear() Else 'Start Excel Err.Clear() Xcel = CType(CreateObject("Excel.Application"), Excel.Application) End If
'Open your File (strBestand is File) XcelBook = CType(Xcel.Workbooks.Open(strBestand), Excel.Workbook) XcelSheet = CType(Xcel.Workbooks(1), Excel.Worksheet)
'Make Excel with worksheet visible Xcel.Application.Visible = True End Sub 'Excel Connection
For VBA for Autocad it is different: Sub ExcelConnection(Optional ByVal strBestand As String) Dim appExcel As Excel.Application Dim Rekenblad As Workbook Dim Tabblad As Worksheet
On Error Resume Next Set appExcel = GetObject(, "Excel.Application") If Err Then Err.Clear Set appExcel = CreateObject("Excel.Application") End If appExcel.Visible = False If strBestand = "" Then Set Rekenblad = appExcel.Workbooks.Add Else Set Rekenblad = appExcel.Workbooks.Open(Bestand) End If appExcel.ScreenUpdating = True Set Tabblad = Rekenblad.Worksheets.Item(1) End Sub
|