psthariharan
06-13-2012, 12:04 AM
Hi
PFA.
i am new to VBA coding. i have used the below code
for find a position and add the contents from a document to word template. But the instance is happening at one time. it is not going to end of document. could any help me. Document is attached from where the contents to be added to word template
Public Function AllCodesIntoTemplate(templateName As String) As Boolean
Dim txtCodeName As String, target As Template, I As Integer
Dim objBB As BuildingBlock
'Adds a whole document of autotext entries into template]
Selection.Find.ClearFormatting
With Selection.Find
.Text = ":BC:"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
While Selection.Find.Execute
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
txtCodeName = Left(Selection, Len(Selection) - 1)
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.Extend
Selection.Find.ClearFormatting
With Selection.Find
.Text = ":EC:"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.MoveLeft Unit:=wdCharacter, Count:=4, Extend:=wdExtend
For I = 1 To Templates.Count
If templateName = Templates(I).Name Then
Set target = Templates(I)
Set objBB = target.BuildingBlockEntries.Add(txtCodeName, wdTypeCustomAutoText, "General", Selection.Range)
'CodeIntoTemplate = True
Selection.ExtendMode = False
Selection.Find.ClearFormatting
With Selection.Find
.Text = ":BC:"
.Forward = True
'.Wrap = wdFindContinue ' wdFindStop
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
End If
Next
Wend
Exitfunction:
Exit Function
End Function
Thanks in advance
PFA.
i am new to VBA coding. i have used the below code
for find a position and add the contents from a document to word template. But the instance is happening at one time. it is not going to end of document. could any help me. Document is attached from where the contents to be added to word template
Public Function AllCodesIntoTemplate(templateName As String) As Boolean
Dim txtCodeName As String, target As Template, I As Integer
Dim objBB As BuildingBlock
'Adds a whole document of autotext entries into template]
Selection.Find.ClearFormatting
With Selection.Find
.Text = ":BC:"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
While Selection.Find.Execute
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
txtCodeName = Left(Selection, Len(Selection) - 1)
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.Extend
Selection.Find.ClearFormatting
With Selection.Find
.Text = ":EC:"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.MoveLeft Unit:=wdCharacter, Count:=4, Extend:=wdExtend
For I = 1 To Templates.Count
If templateName = Templates(I).Name Then
Set target = Templates(I)
Set objBB = target.BuildingBlockEntries.Add(txtCodeName, wdTypeCustomAutoText, "General", Selection.Range)
'CodeIntoTemplate = True
Selection.ExtendMode = False
Selection.Find.ClearFormatting
With Selection.Find
.Text = ":BC:"
.Forward = True
'.Wrap = wdFindContinue ' wdFindStop
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
End If
Next
Wend
Exitfunction:
Exit Function
End Function
Thanks in advance