N
NettysGirl_mi
Word 2003 on Windows XP. My template will be used to create design documents
with up to 12 different sections ("sections" meaning blocks of text, no
Section Breaks involved). Examples of sections are Requirements,
Assumptions, Calculations, Examples, etc. I have defined AutoText entries
for each of the variations that can occur for each of the sections. For
example, there are AutoText entries for RequirementsA, RequirementsB,
AssumptionsA, etc. Thanks to one of the MVP websites, I now have a userform
with 12 comboboxes that list out all of the AutoText entries, so users can
select which sections/variations they want included in the document, in
order. Here is the coding for that (which works great):
-------------------------------------
Sub showSelectSectionsForm()
Dim i As Long,
Dim UFrm As form_SelectSections
Dim arrAutoText() As String
Set UFrm = form_SelectSections
ReDim
arrAutoText(ActiveDocument.AttachedTemplate.AutoTextEntries.Count - 1)
For i = 0 To ActiveDocument.AttachedTemplate.AutoTextEntries.Count - 1
arrAutoText(i) = ActiveDocument.AttachedTemplate.AutoTextEntries(i +
1).Name
Next i
WordBasic.SortArray arrAutoText()
UFrm.cbx_Selection01.List = arrAutoText()
UFrm.cbx_Selection02.List = arrAutoText()
……
UFrm.cbx_Selection12.List = arrAutoText()
With UFrm
.Show vbModeless
End With
End Sub
-----------------------------------------
Now I need to write up my OK button click event, and I can't figure it out.
Here is a macro that I recorded that shows what I am trying to accomplish
(kind of –the recorder is limited of course).
The first AutoText will always be inserted at Bookmark "Insert_Sections".
All AutoTexts in this template end with a bookmark called "Insert_Next", so
each subsequent AutoText will be inserted after the previous one (and the
previous "Insert_Next" bookmark is replaced by one at the end of this new
AutoText).
----------------------------------
Selection.GoTo What:=wdGoToBookmark, Name:="Insert_Sections"
ActiveDocument.AttachedTemplate.AutoTextEntries( _
"1 Requirements ").Insert Where:=Selection.Range, RichText:= _
True
Selection.GoTo What:=wdGoToBookmark, Name:="Insert_Next"
Selection.TypeParagraph
ActiveDocument.AttachedTemplate.AutoTextEntries( _
"4 Assumptions-Source ").Insert Where:=Selection.Range, _
RichText:=True
Selection.GoTo What:=wdGoToBookmark, Name:="Insert_Next"
Selection.TypeParagraph
ActiveDocument.AttachedTemplate.AutoTextEntries( _
"5 Assumptions-Destination").Insert Where:=Selection.Range, _
RichText:=True
----------------------------------
I can't figure out how to replace the literal name of the AutoText entry
(such as "1 Requirements") with the option selected in cbx_Selection01, then
the next one ("4 Assumptions-Source") with the option selected in
cbx_Selection02, etc. I know how to return the index value, but that just
tells me where in the list the selection falls. I don't know how I would use
that to determine the AutoText name.
Also, it seems like there should be a way to loop through this without
having to specify each individual combobox name, but again, I'm not sure how
to replace the literal with a variable to use in a for/next loop.
Any suggestions are much appreciated.
with up to 12 different sections ("sections" meaning blocks of text, no
Section Breaks involved). Examples of sections are Requirements,
Assumptions, Calculations, Examples, etc. I have defined AutoText entries
for each of the variations that can occur for each of the sections. For
example, there are AutoText entries for RequirementsA, RequirementsB,
AssumptionsA, etc. Thanks to one of the MVP websites, I now have a userform
with 12 comboboxes that list out all of the AutoText entries, so users can
select which sections/variations they want included in the document, in
order. Here is the coding for that (which works great):
-------------------------------------
Sub showSelectSectionsForm()
Dim i As Long,
Dim UFrm As form_SelectSections
Dim arrAutoText() As String
Set UFrm = form_SelectSections
ReDim
arrAutoText(ActiveDocument.AttachedTemplate.AutoTextEntries.Count - 1)
For i = 0 To ActiveDocument.AttachedTemplate.AutoTextEntries.Count - 1
arrAutoText(i) = ActiveDocument.AttachedTemplate.AutoTextEntries(i +
1).Name
Next i
WordBasic.SortArray arrAutoText()
UFrm.cbx_Selection01.List = arrAutoText()
UFrm.cbx_Selection02.List = arrAutoText()
……
UFrm.cbx_Selection12.List = arrAutoText()
With UFrm
.Show vbModeless
End With
End Sub
-----------------------------------------
Now I need to write up my OK button click event, and I can't figure it out.
Here is a macro that I recorded that shows what I am trying to accomplish
(kind of –the recorder is limited of course).
The first AutoText will always be inserted at Bookmark "Insert_Sections".
All AutoTexts in this template end with a bookmark called "Insert_Next", so
each subsequent AutoText will be inserted after the previous one (and the
previous "Insert_Next" bookmark is replaced by one at the end of this new
AutoText).
----------------------------------
Selection.GoTo What:=wdGoToBookmark, Name:="Insert_Sections"
ActiveDocument.AttachedTemplate.AutoTextEntries( _
"1 Requirements ").Insert Where:=Selection.Range, RichText:= _
True
Selection.GoTo What:=wdGoToBookmark, Name:="Insert_Next"
Selection.TypeParagraph
ActiveDocument.AttachedTemplate.AutoTextEntries( _
"4 Assumptions-Source ").Insert Where:=Selection.Range, _
RichText:=True
Selection.GoTo What:=wdGoToBookmark, Name:="Insert_Next"
Selection.TypeParagraph
ActiveDocument.AttachedTemplate.AutoTextEntries( _
"5 Assumptions-Destination").Insert Where:=Selection.Range, _
RichText:=True
----------------------------------
I can't figure out how to replace the literal name of the AutoText entry
(such as "1 Requirements") with the option selected in cbx_Selection01, then
the next one ("4 Assumptions-Source") with the option selected in
cbx_Selection02, etc. I know how to return the index value, but that just
tells me where in the list the selection falls. I don't know how I would use
that to determine the AutoText name.
Also, it seems like there should be a way to loop through this without
having to specify each individual combobox name, but again, I'm not sure how
to replace the literal with a variable to use in a for/next loop.
Any suggestions are much appreciated.