> Виктор
Можно так:
Option Explicit
'' Ссылка на библиотеку:
'' Tools->References -> Microsof Excel 1X.0 Object Library
'' Обработка ошибок:
'' Tools->Options->General->Break on Unhandled Errors
Sub GetExcel()
'' Author : Ken Puls (www.excelguru.ca)
'' Bind to an existing or created instance of Microsoft Excel
Dim objApp As Object
Dim objWbk As Object
Dim flName As String
'Attempt to bind to an open instance
On Error Resume Next
Set objApp = GetObject(, "Excel.Application")
If Err.Number <> 0 Then
'Could not get instance, so create a new one
Err.Clear
On Error GoTo ErrHandler
Set objApp = CreateObject("Excel.Application")
With objApp
.Visible = True
.Workbooks.Add
End With
Else
'Bound to instance, activate error handling
On Error GoTo ErrHandler
End If
' Get active document (last opened should active)
Set objWbk = objApp.ActiveWorkbook
' Add some text to the document
With objWbk
.Worksheets(1).Activate
.Worksheets(1).Cells(1, 1) = "boxtext1"
.Worksheets(1).Cells(1, 2) = "dollar"
.Worksheets(1).Cells(1, 3) = "boxtext1" & "dollar"
End With
' Build the full path to save file
flName = ThisDrawing.Path & "\Test001.xls"
' Save and close document
objWbk.SaveAs flName
objWbk.Close
' Quit application instance
objApp.Quit
ErrHandler:
If Err.Number <> 0 Then
' Display error message
MsgBox Err.Description & " <--> " & Err.Number
End If
' Release all objects and resume normal error handling
Set objWbk = Nothing
Set objApp = Nothing
On Error GoTo 0
End Sub
Кстати, все коды есть в справочной системе Excel,
открой любой файл Эксель, иди в редактор VBA (Alt+F11)
там в Хэлпе все есть
~'J'~