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 71 72 73 74 75 76 77
|
Public Function Active_Word(cBronSource, cSourceData As String, cSQL As String, Optional lPrint As Boolean = False) As Boolean
Dim oApp As Object, cErr As String, aDoc, lFlag As String, cConnection As String * 255, j As Integer
On Error GoTo Err_Active_Word
Active_Word = False
cConnection = Left("Provider=Microsoft.Jet.OLEDB.4.0;Password="""";User ID=Admin;Data Source=" & cSourceData & ";Mode=Read;Extended Properties=""HDR=YES;IMEX=1;"";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Database Passwo", 255)
Set oApp = CreateObject("Word.Application")
oApp.Visible = Not lPrint
oApp.Documents.Open filename:=cBronSource, ConfirmConversions:=False, _
ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="", _
PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _
WritePasswordTemplate:="", Format:=wdOpenFormatAuto
With oApp.ActiveDocument.MailMerge
.OpenDataSource Name:=cSourceData, _
ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True, _
AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:="", _
WritePasswordDocument:="", WritePasswordTemplate:="", Revert:=False, _
Format:=wdOpenFormatAuto, Connection:=cConnection, SQLStatement:=cSQL, SQLStatement1 _
:="", SubType:=wdMergeSubTypeAccess
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=True
End With
Do
'boucle pour enlever de la fenêtre word les documents types
lFlag = True
'MsgBox "Fermeture des documents vierges"
'Update_MsgBox Donne_Message(175)
For Each aDoc In oApp.Documents
If InList("P26;BRI;ESE;DOC", UCase(Left(aDoc.Name, 3))) Then
oApp.Documents(aDoc.Name).Activate
'Update_MsgBox "Fermeture du document " & aDoc.Name
'Update_MsgBox Donne_Message(174) & aDoc.Name
oApp.ActiveDocument.Close False
lFlag = False
Exit For
End If
Next aDoc
Loop Until lFlag
If lPrint Then ' si impresion directe alors fermeture des documents
For j = oApp.Documents.Count To 1 Step -1
oApp.Documents(j).Activate
'Update_MsgBox "Impression du document " & oApp.Documents(1).Name & " vers l'imprimante par défaut"
'Update_MsgBox Replace(Donne_Message(176), "%1%", oApp.Documents(j).Name)
oApp.Documents(j).PrintOut
oApp.ActiveDocument.Close False
DoEvents
Next j
End If
Active_Word = True
Exit_Err_Active_Word:
Set oApp = Nothing
'Close_MsgBox
Exit Function
Err_Active_Word:
'Ouvre_MsgBox "Erreur ouverture word " & Err.Number, " " & Err.Description, 1, 5
cErr = "WORD ERR" & vbCrLf & "Txt Source := " & cBronSource & vbCrLf & _
"Data source := " & cSourceData & vbCrLf & _
"FILTRE SQL := " & cSQL
'Rec_err Err.Number, Err.Description, Err.Source, cErr
Resume Next
End Function
Public Function InList(cOu As String, cQuoi As String) As Boolean
Dim aTable, j As Integer
aTable = Split(cOu, ";")
For j = 0 To UBound(aTable, 1)
If cQuoi = aTable(j) Then InList = True: Exit Function
Next j
InList = False
End Function
jojo5650 |
Partager