J'utilise une base Access pour créer des soumissions.
À partir d'une programmation VB dans Access, je remplace des champs dans un
document Word.
J'utilise une table de remplacement de caractère.
Ca fonctionne bien, sauf que les champs situés dans l'entête et pied de page
ne sont pas changé.
Comment faire
Merci
Note:voir une partie de mon code ci-bas
Dim WordApp As Word.Application
Dim WordDoc As Word.Document
Dim rsForm As New ADODB.Recordset
Dim rsFormCode As New ADODB.Recordset
Dim rsFormData As New ADODB.Recordset
Dim strQuery As String
Dim Cn As ADODB.Connection
Set Cn = CurrentProject.Connection
rsForm.Open "Select * from tblForm where IDForm=" &
cboForm.ItemData(cboForm.ListIndex), Cn, adOpenStatic, adLockOptimistic
If Not rsForm.EOF Then
strQuery = rsForm!strQuery
Set WordApp = New Word.Application
WordApp.Visible = True
'-- Get the application's path and establish the final file name
strCurrAppDir = rsForm!strFilePath
If Right(strCurrAppDir, 1) <> "\" Then strCurrAppDir = strCurrAppDir
& "\"
strFinalDoc = strCurrAppDir & rsForm!strcopyFilename
'-- Copy the template so it doesn't get written over.
FileCopy strCurrAppDir & rsForm!strsourceFilename, strFinalDoc
rsFormCode.Open "Select * from tblFormCode where IDForm=" &
cboForm.ItemData(cboForm.ListIndex), Cn, adOpenStatic, adLockOptimistic
Do Until rsFormCode.EOF
If Len(Trim(rsFormCode!strFieldName & "")) > 0 Then
With docWord.Content.Find
.Execute FindText:=rsFormCode!strCode, _
ReplaceWith:=CStr(rsFormData.Fields(CStr(rsFormCode!strFieldName)).Value
& ""), Format:=True, _
Replace:=wdReplaceAll
End With
Else
With docWord.Content.Find
.Execute FindText:=rsFormCode!strCode, _
ReplaceWith:="", Format:=True, _
Replace:=wdReplaceAll
End With
End If
rsFormCode.MoveNext
Loop
rsFormCode.Close
Set rsFormCode = Nothing
rsFormData.Close
Set rsFormData = Nothing
Cette action est irreversible, confirmez la suppression du commentaire ?
Signaler le commentaire
Veuillez sélectionner un problème
Nudité
Violence
Harcèlement
Fraude
Vente illégale
Discours haineux
Terrorisme
Autre
Circé
Bonjour Robert Parise,
C'est normal, tu fais une recherche dans le document principal, mais pas dans la partie entête/pdp qui es traitée à part.
Tu peux t'inspirer du code suivant pour intégrer la recherche dans les entêtes et pdp : http://faqword.free.fr/articles.php?lng=fr&pg95" target="_blank" class="text-blue hover:opacity-90 " style="word-break: break-all;" rel="noopener nofollow">http://faqword.free.fr/articles.php?lng=fr&pg95
J'utilise une base Access pour créer des soumissions. À partir d'une programmation VB dans Access, je remplace des champs dans un document Word. J'utilise une table de remplacement de caractère. Ca fonctionne bien, sauf que les champs situés dans l'entête et pied de page ne sont pas changé.
Comment faire
Merci
Note:voir une partie de mon code ci-bas
Dim WordApp As Word.Application Dim WordDoc As Word.Document Dim rsForm As New ADODB.Recordset Dim rsFormCode As New ADODB.Recordset Dim rsFormData As New ADODB.Recordset Dim strQuery As String Dim Cn As ADODB.Connection Set Cn = CurrentProject.Connection rsForm.Open "Select * from tblForm where IDForm=" & cboForm.ItemData(cboForm.ListIndex), Cn, adOpenStatic, adLockOptimistic If Not rsForm.EOF Then strQuery = rsForm!strQuery Set WordApp = New Word.Application WordApp.Visible = True
'-- Get the application's path and establish the final file name strCurrAppDir = rsForm!strFilePath If Right(strCurrAppDir, 1) <> "" Then strCurrAppDir = strCurrAppDir & ""
strFinalDoc = strCurrAppDir & rsForm!strcopyFilename '-- Copy the template so it doesn't get written over. FileCopy strCurrAppDir & rsForm!strsourceFilename, strFinalDoc
rsFormCode.Open "Select * from tblFormCode where IDForm=" & cboForm.ItemData(cboForm.ListIndex), Cn, adOpenStatic, adLockOptimistic
Do Until rsFormCode.EOF If Len(Trim(rsFormCode!strFieldName & "")) > 0 Then With docWord.Content.Find .Execute FindText:=rsFormCode!strCode, _
ReplaceWith:=CStr(rsFormData.Fields(CStr(rsFormCode!strFieldName)).Value & ""), Format:=True, _ Replace:=wdReplaceAll End With Else With docWord.Content.Find .Execute FindText:=rsFormCode!strCode, _ ReplaceWith:="", Format:=True, _ Replace:=wdReplaceAll End With
End If
rsFormCode.MoveNext Loop rsFormCode.Close Set rsFormCode = Nothing rsFormData.Close Set rsFormData = Nothing
End If rsForm.Close Set rsForm = Nothing
Bonjour Robert Parise,
C'est normal, tu fais une recherche dans le document principal, mais
pas dans la partie entête/pdp qui es traitée à part.
Tu peux t'inspirer du code suivant pour intégrer la recherche dans les
entêtes et pdp :
http://faqword.free.fr/articles.php?lng=fr&pg95
Circé
http://faqword.free.fr
Robert Parise a formulé la demande :
Bonjour
J'utilise une base Access pour créer des soumissions.
À partir d'une programmation VB dans Access, je remplace des champs dans un
document Word.
J'utilise une table de remplacement de caractère.
Ca fonctionne bien, sauf que les champs situés dans l'entête et pied de page
ne sont pas changé.
Comment faire
Merci
Note:voir une partie de mon code ci-bas
Dim WordApp As Word.Application
Dim WordDoc As Word.Document
Dim rsForm As New ADODB.Recordset
Dim rsFormCode As New ADODB.Recordset
Dim rsFormData As New ADODB.Recordset
Dim strQuery As String
Dim Cn As ADODB.Connection
Set Cn = CurrentProject.Connection
rsForm.Open "Select * from tblForm where IDForm=" &
cboForm.ItemData(cboForm.ListIndex), Cn, adOpenStatic, adLockOptimistic
If Not rsForm.EOF Then
strQuery = rsForm!strQuery
Set WordApp = New Word.Application
WordApp.Visible = True
'-- Get the application's path and establish the final file name
strCurrAppDir = rsForm!strFilePath
If Right(strCurrAppDir, 1) <> "" Then strCurrAppDir = strCurrAppDir
& ""
strFinalDoc = strCurrAppDir & rsForm!strcopyFilename
'-- Copy the template so it doesn't get written over.
FileCopy strCurrAppDir & rsForm!strsourceFilename, strFinalDoc
rsFormCode.Open "Select * from tblFormCode where IDForm=" &
cboForm.ItemData(cboForm.ListIndex), Cn, adOpenStatic, adLockOptimistic
Do Until rsFormCode.EOF
If Len(Trim(rsFormCode!strFieldName & "")) > 0 Then
With docWord.Content.Find
.Execute FindText:=rsFormCode!strCode, _
ReplaceWith:=CStr(rsFormData.Fields(CStr(rsFormCode!strFieldName)).Value &
""), Format:=True, _
Replace:=wdReplaceAll
End With
Else
With docWord.Content.Find
.Execute FindText:=rsFormCode!strCode, _
ReplaceWith:="", Format:=True, _
Replace:=wdReplaceAll
End With
End If
rsFormCode.MoveNext
Loop
rsFormCode.Close
Set rsFormCode = Nothing
rsFormData.Close
Set rsFormData = Nothing
C'est normal, tu fais une recherche dans le document principal, mais pas dans la partie entête/pdp qui es traitée à part.
Tu peux t'inspirer du code suivant pour intégrer la recherche dans les entêtes et pdp : http://faqword.free.fr/articles.php?lng=fr&pg95" target="_blank" class="text-blue hover:opacity-90 " style="word-break: break-all;" rel="noopener nofollow">http://faqword.free.fr/articles.php?lng=fr&pg95
J'utilise une base Access pour créer des soumissions. À partir d'une programmation VB dans Access, je remplace des champs dans un document Word. J'utilise une table de remplacement de caractère. Ca fonctionne bien, sauf que les champs situés dans l'entête et pied de page ne sont pas changé.
Comment faire
Merci
Note:voir une partie de mon code ci-bas
Dim WordApp As Word.Application Dim WordDoc As Word.Document Dim rsForm As New ADODB.Recordset Dim rsFormCode As New ADODB.Recordset Dim rsFormData As New ADODB.Recordset Dim strQuery As String Dim Cn As ADODB.Connection Set Cn = CurrentProject.Connection rsForm.Open "Select * from tblForm where IDForm=" & cboForm.ItemData(cboForm.ListIndex), Cn, adOpenStatic, adLockOptimistic If Not rsForm.EOF Then strQuery = rsForm!strQuery Set WordApp = New Word.Application WordApp.Visible = True
'-- Get the application's path and establish the final file name strCurrAppDir = rsForm!strFilePath If Right(strCurrAppDir, 1) <> "" Then strCurrAppDir = strCurrAppDir & ""
strFinalDoc = strCurrAppDir & rsForm!strcopyFilename '-- Copy the template so it doesn't get written over. FileCopy strCurrAppDir & rsForm!strsourceFilename, strFinalDoc
rsFormCode.Open "Select * from tblFormCode where IDForm=" & cboForm.ItemData(cboForm.ListIndex), Cn, adOpenStatic, adLockOptimistic
Do Until rsFormCode.EOF If Len(Trim(rsFormCode!strFieldName & "")) > 0 Then With docWord.Content.Find .Execute FindText:=rsFormCode!strCode, _
ReplaceWith:=CStr(rsFormData.Fields(CStr(rsFormCode!strFieldName)).Value & ""), Format:=True, _ Replace:=wdReplaceAll End With Else With docWord.Content.Find .Execute FindText:=rsFormCode!strCode, _ ReplaceWith:="", Format:=True, _ Replace:=wdReplaceAll End With
End If
rsFormCode.MoveNext Loop rsFormCode.Close Set rsFormCode = Nothing rsFormData.Close Set rsFormData = Nothing