PDA

View Full Version : Solved: Insert Header and Macrobutton with loop



Novio
01-22-2013, 01:51 AM
Hello,

I have a question.
I want to please with loop a Header and macrobutton.

The output should be like:
header 1
"Picture Insert"
header 2
etc

I have this code:
Sub test()
index = 0
Do Until index = 5
index = index + 1
Selection.Style = "Header 1"
Selection.Text = "Header 1"
Selection.TypeParagraph
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
"MACROBUTTON StartProcess ""Insert Picture"" ", PreserveFormatting:=False
Loop
End Sub

Please help

Kind regards


Mark

gmaxey
01-22-2013, 06:31 AM
Assuming your meant "Headings" and "Heading 1":

Sub test()
Dim Index As Long
Index = 0
Do Until Index = 5
Index = Index + 1
Selection.Style = "Heading 1"
Selection.InsertAfter "Header " & Index & vbCr
Selection.Collapse wdCollapseEnd
Selection.Style = "Normal"
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
"MACROBUTTON StartProcess ""Insert Picture""", PreserveFormatting:=False
If Index < 5 Then
Selection.InsertBefore vbCr
Selection.Move wdCharacter, 1
End If
Loop
End Sub

Novio
01-22-2013, 08:31 AM
Thanks Greg.

It works fine.

Kind Regards

Mark