1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
| Private Sub Commande127_Click()
' PUBLI VBA
On Error GoTo Macroetiquette_Err
DoCmd.SetWarnings False
DoCmd.OpenQuery "Rapport visite_Auto"
DoCmd.SetWarnings True
DoCmd.RefreshRecord
'Ouverture du Word via une fenêtre de sélection
Dim fDialog As Office.FileDialog
Dim varFile As Variant
Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
With fDialog
' Allow user to make multiple selections in dialog box
.AllowMultiSelect = False
' Set the title of the dialog box.
.Title = "Please select one or more files"
' Clear out the current filters, and add our own.
.Filters.Clear
.Filters.Add "All Files", "*.DOCX"
If .Show = True Then
For Each varFile In .SelectedItems
MsgBox "Le fichier Word va s'ouvrir, attendez quelques secondes..."
' Voici pour la déclaration du code :
Dim wdapp As Word.Application
' Démarrer Word
Set wdapp = CreateObject("Word.application")
Dim wddoc As Word.Document
With wdapp
.Visible = True
' Ouvrir le document
Set wddoc = .Documents.Open(CStr(varFile))
' Diriger le publipostage vers un nouveau document
.ActiveDocument.MailMerge.Execute
On Error GoTo SAVE_Err
.ActiveDocument.Save
wddoc.Close
Goto next01
SAVE_Err:
MsgBox "Attention, vous n'avez pas sauvé votre rapport !?"
next01:
End With
' Fermer et libérer les objets
Set wdapp = Nothing
Next
End If
End With
GoTo finish
'=========================
Macroetiquette_Err:
MsgBox "Erreur !"
finish:
End Sub |
Partager