Hello,
Here is an example of the use of the CreateObject("Excel.Application")
function. You could also study the GetObject function in the Help.
This example reads an Excel workbook, you can adapt it to write in a Word
document
Hope this helps
Gérard Ducouret
---------------------
Sub ImportationExcel_4c()
Dim XLApp As Object 'Excel.Application
Dim Chemin As String, Clic As Integer
Dim NomClasseurXL As String, NomTache As String
Dim No As Integer
Dim oDialog As FileDialog 'Create a
FileDialog object
'Create a FileDialog object as a File Picker dialog box:
Set oDialog = Application.FileDialog(msoFileDialogFilePicker) 'Ouvre
une boîte de dialogue MS Office FilePicker : 'Create a FileDialog object as
a File Picker dialog box.
oDialog.InitialFileName = "D:\Mes documents\DT a traiter\" 'Set the
initial path to the D:\ drive.
oDialog.Filters.Add "Fichiers Excel", "*.xls" 'Sélection
sur les classeurs .XLS
oDialog.Title = "Sélectionnez le fichier Excel" 'Titre de la
boîte de dialogue
oDialog.AllowMultiSelect = False 'Pas de
sélection multiple
If oDialog.Show = 0 Then
'Affiche la boîte de dialogue MS Office FilePicker
MsgBox "Opération annulée", vbExclamation, "Pas d'importation à
partir d'Excel"
Exit Sub
Else
If oDialog.SelectedItems.Count > 0 Then
NomClasseurXL = oDialog.SelectedItems(1)
Set XLApp = CreateObject("Excel.Application")
XLApp.Visible = False
End If
End If
Set oDialog = Nothing
XLApp.WorkBooks.Open NomClasseurXL
XLApp.Visible = False
With XLApp
'Do a lot of things here...
End With
'Application.ScreenUpdating = True
MsgBox "Importation des données Excel terminée", vbInformation, "Génération
demande via Excel"
XLApp.ActiveWorkbook.Close SaveChanges:=False 'Ferme le Classeur sans
sauvegarde !
XLApp.Quit
Set XLApp = Nothing
End Sub