there's a for each
you are not finishing
If InStr(ActiveDocument.ContentControls(1).Range.Text, "ISWPPP") Then
For Each oPara In ActiveDocument.ListParagraphs
and at the end of all
End If
Next oPara
题
I have a document with a list in the list format. I tried combining two subs as you can tell in changebullet
with findbullet
. I'm trying to get findbullet
to cycle through the document and go to a new list in the list index. I'm then trying to use changebullet
to cycle through if statements to see if a string exist in the contentcontrol( i debated using Selectcase
).
The Idea is to pick an item in the dropdown list of the content control (in this case ContentControls(1)) and then click a command button to trigger Changebullet
. You can see my bullet list that is trying to be entered in the code. With out all the mumbo jumbo at the top of changebullet
it generates a list just fine in the "symbol" font style.It just wont add the bullets to the list lastly it wont maintain the font of the text as "Times New Roman" it changes everything to Symbol (only the bullets need to be symbol).
I'm running into compile errors regarding for statements already in use or an error where End with is not found or end if is not found.
UPDATE/EDIT: I went through some iterations and fixed my problems. Below is the list of errors and then the list of fixes.
To fix the issues
ActiveDocument.Lists(1).Range.Select
this allowed the macro to only interact with the list I was trying to manipulate "List 1" ContinuePreviousList:=True
This allowed the text insertion to display bullets and kept List 1.Things I took away from this miss hap. Get the Macro to either select the section I wish to interact with or get the cursor to move where I want interact with the Document. To keep the list index from breaking and to add/adjust the bullet list make continue previous list equal true.
)
Sub changebullets ()
Dim oPara As Word.Paragraph
Dim i As Long
Dim HCE As Long
Dim CntCtrl As Variant
CntCtrl = ActiveDocument.ContentControls(1).Range.Text
HCE = ActiveDocument.Lists.Count
With Selection
If InStr(ActiveDocument.ContentControls(1).Range.Text, "DropDownItem1") Then
ActiveDocument.Lists(1).Range.Select
ListGalleries(wdBulletGallery).ListTemplates(1).Name = ""
Selection.Range.ListFormat.ApplyListTemplateWithLevel ListTemplate:=ListGalleries(wdBulletGallery).ListTemplates(1), ContinuePreviousList:=True, ApplyTo:=wdListApplyToSelection, DefaultListBehavior:=wdWord10ListBehavior
With ListGalleries(wdBulletGallery).ListTemplates(1).ListLevels(1)
.NumberFormat = ChrW(61623)
.TrailingCharacter = wdTrailingTab
.NumberStyle = wdListNumberStyleBullet
.NumberPosition = InchesToPoints(0.25)
.Alignment = wdListLevelAlignLeft
.TextPosition = InchesToPoints(0.25)
.TabPosition = wdUndefined
.ResetOnHigher = 0
.StartAt = 1
With .Font
.Size = 8
.Name = "Symbol"
End With
.LinkedStyle = ""
End With
Selection.Font.Name = "Times New Roman"
Selection.TypeText Text:="Hello does it work yet?"
Selection.TypeParagraph
Selection.TypeText Text:="New Bullet Mother Trucker."
Selection.TypeParagraph
Selection.TypeText Text:="Second Bullet Mother Trucker."
Selection.TypeParagraph
Selection.TypeText Text:="Third Bullet Mother Trucker."
Selection.TypeParagraph
Selection.TypeText Text:="Fourth Bullet Mother Trucker."
End If
If InStr(ActiveDocument.ContentControls(1).Range.Text, "DropDownItem2") Then
ActiveDocument.Lists(1).Range.Select
ListGalleries(wdBulletGallery).ListTemplates(1).Name = ""
Selection.Range.ListFormat.ApplyListTemplateWithLevel ListTemplate:=ListGalleries(wdBulletGallery).ListTemplates(1), ContinuePreviousList:=True, ApplyTo:=wdListApplyToSelection, DefaultListBehavior:=wdWord10ListBehavior
With ListGalleries(wdBulletGallery).ListTemplates(1).ListLevels(1)
.NumberFormat = ChrW(61623)
.TrailingCharacter = wdTrailingTab
.NumberStyle = wdListNumberStyleBullet
.NumberPosition = InchesToPoints(0.25)
.Alignment = wdListLevelAlignLeft
.TextPosition = InchesToPoints(0.5)
.TabPosition = wdUndefined
.ResetOnHigher = 0
.StartAt = 1
With .Font
.Size = 8
.Animation = wdUndefined
.DoubleStrikeThrough = wdUndefined
.Name = "Symbol"
End With
.LinkedStyle = ""
End With
Selection.Font.Name = "Times New Roman"
Selection.TypeText Text:="Xtina is a well dressed Environmental Scientist."
Selection.TypeParagraph
Selection.TypeText Text:="Micah has King Ranch Chicken that he'd like to eat."
Selection.TypeParagraph
Selection.TypeText Text:="Where you ever in college."
Selection.TypeParagraph
Selection.TypeText Text:="Josh is a Madman and he has Tattoos."
Selection.TypeParagraph
Selection.TypeText Text:="Fourth Bullet Mother Trucker."
End If
If InStr(ActiveDocument.ContentControls(1).Range.Text, "DropDownItem3") Then
ActiveDocument.Lists(1).Range.Select
ListGalleries(wdBulletGallery).ListTemplates(1).Name = ""
Selection.Range.ListFormat.ApplyListTemplateWithLevel ListTemplate:=ListGalleries(wdBulletGallery).ListTemplates(1), ContinuePreviousList:=True, ApplyTo:=wdListApplyToSelection, DefaultListBehavior:=wdWord10ListBehavior
With ListGalleries(wdBulletGallery).ListTemplates(1).ListLevels(1)
.NumberFormat = ChrW(61623)
.TrailingCharacter = wdTrailingTab
.NumberStyle = wdListNumberStyleBullet
.NumberPosition = InchesToPoints(0.25)
.Alignment = wdListLevelAlignLeft
.TextPosition = InchesToPoints(0.5)
.TabPosition = wdUndefined
.ResetOnHigher = 0
.StartAt = 1
With .Font
.Size = 8
.Animation = wdUndefined
.DoubleStrikeThrough = wdUndefined
.Name = "Symbol"
End With
.LinkedStyle = ""
End With
Selection.Font.Name = "Times New Roman"
Selection.TypeText Text:="Dick Whitmen."
Selection.TypeParagraph
Selection.TypeText Text:="Wagner."
Selection.TypeParagraph
Selection.TypeText Text:="Gesting."
Selection.TypeParagraph
Selection.TypeText Text:="Jasmin."
Selection.TypeParagraph
Selection.TypeText Text:="Fourth Bullet Mother Trucker."
End If
If InStr(ActiveDocument.ContentControls(1).Range.Text, "DropDownItem4") Then
ActiveDocument.Lists(1).Range.Select
ListGalleries(wdBulletGallery).ListTemplates(1).Name = ""
Selection.Range.ListFormat.ApplyListTemplateWithLevel ListTemplate:=ListGalleries(wdBulletGallery).ListTemplates(1), ContinuePreviousList:=True, ApplyTo:=wdListApplyToSelection, DefaultListBehavior:=wdWord10ListBehavior
With ListGalleries(wdBulletGallery).ListTemplates(1).ListLevels(1)
.NumberFormat = ChrW(61623)
.TrailingCharacter = wdTrailingTab
.NumberStyle = wdListNumberStyleBullet
.NumberPosition = InchesToPoints(0.25)
.Alignment = wdListLevelAlignLeft
.TextPosition = InchesToPoints(0.5)
.TabPosition = wdUndefined
.ResetOnHigher = 0
.StartAt = 1
With .Font
.Size = 8
.Name = "Symbol"
End With
.LinkedStyle = ""
End With
Selection.Font.Name = "Times New Roman"
Selection.TypeText Text:="Ready Mix."
Selection.TypeParagraph
Selection.TypeText Text:="Dump Trucks doing Stuff."
Selection.TypeParagraph
Selection.TypeText Text:="Mad men is a crazy show."
Selection.TypeParagraph
Selection.TypeText Text:="The IBM computer was installed."
Selection.TypeParagraph
Selection.TypeText Text:="Stubblefield Coddington Whinchell 3rd."
End If
End With
End Sub
解决方案
there's a for each
you are not finishing
If InStr(ActiveDocument.ContentControls(1).Range.Text, "ISWPPP") Then
For Each oPara In ActiveDocument.ListParagraphs
and at the end of all
End If
Next oPara