From: NettysGirl_mi on
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.

From: Fumei2 via OfficeKB.com on
YOU have to work out the logic. YOU have to make the decisions.

One way to make it easier (but I am not sure it will work for you in this
case) is to match item names in the combobox with the AutoText names.

What I am not following is this: "I now have a userform with 12 comboboxes "

Is this literally true? You have 12 comboboxes, and each combobox (I assume)
has multiple items? It sort of looks lik eeach comboboxc gets filled with
the SAME items.

UFrm.cbx_Selection01.List = arrAutoText()
UFrm.cbx_Selection02.List = arrAutoText()

If this is the case, I have to ask why?

In any case, you already have an array of the AutoText, so match each item in
the array to an item in the combobox.


NettysGirl_mi wrote:
>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.

--
Gerry

Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.aspx/word-programming/201003/1

From: NettysGirl_mi on
(I'm going to call my initial bookmark "Insert_Next" like the others, so the
first insert can be handled just like the others.)

"NettysGirl_mi" wrote:

> 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.
>
 | 
Pages: 1
Prev: Pasting a picture
Next: File can not open