D
Dave
Let me say up front that I am not a programmer but, that through the
kindness of strangers who post their Word macros on the Web and answer
questions, I've been able to pull together simple macros that meet my
needs.
My current question is how to add a checkbox to the beginning of each
paragraph in a new document that is developed by pulling the headings
from an existing document. I've put in a comment where the checkbox
needs to go. All of the examples I've found for adding a checkbox
don't work in this instance.
Thanks in advance
Sub PrintHeadings()
' Creates a new document with Heading XX
' style paragraphs only from active document.
' User prompted for max level XX.
Dim para As Paragraph, rng As Range
Dim DocA As Document, DocB As Document
Dim iLevel As Integer, iMaxLevel As Integer
Dim HeadCount As Integer
' Ask for max level
iMaxLevel = InputBox("Enter maximum level of Headings to Include:")
If iMaxLevel = 0 Then Exit Sub
Set DocA = ActiveDocument
' Create new document
Set DocB = Word.Documents.Add(DocA.AttachedTemplate.Name)
Set rng = DocB.Range
HeadCount = 0
'Include text from another file
For Each para In DocA.Paragraphs
DoEvents
iLevel = 0
' Check for Heading style
If para.Format.Style Like "Heading [0-9]" Then
iLevel = Val(Mid(para.Format.Style, 8))
' Check for acceptable level
If iLevel > 0 And iLevel <= iMaxLevel Then
HeadCount = HeadCount + 1
'Add an option button before each paragraph
'Use HeadCount as part of button name
rng.Collapse wdCollapseEnd
rng.Text = String((iLevel - 1) * 4, " ") & _
Format(iLevel) & ") " & para.Range.Text
End If
End If
Next para
End Sub
kindness of strangers who post their Word macros on the Web and answer
questions, I've been able to pull together simple macros that meet my
needs.
My current question is how to add a checkbox to the beginning of each
paragraph in a new document that is developed by pulling the headings
from an existing document. I've put in a comment where the checkbox
needs to go. All of the examples I've found for adding a checkbox
don't work in this instance.
Thanks in advance
Sub PrintHeadings()
' Creates a new document with Heading XX
' style paragraphs only from active document.
' User prompted for max level XX.
Dim para As Paragraph, rng As Range
Dim DocA As Document, DocB As Document
Dim iLevel As Integer, iMaxLevel As Integer
Dim HeadCount As Integer
' Ask for max level
iMaxLevel = InputBox("Enter maximum level of Headings to Include:")
If iMaxLevel = 0 Then Exit Sub
Set DocA = ActiveDocument
' Create new document
Set DocB = Word.Documents.Add(DocA.AttachedTemplate.Name)
Set rng = DocB.Range
HeadCount = 0
'Include text from another file
For Each para In DocA.Paragraphs
DoEvents
iLevel = 0
' Check for Heading style
If para.Format.Style Like "Heading [0-9]" Then
iLevel = Val(Mid(para.Format.Style, 8))
' Check for acceptable level
If iLevel > 0 And iLevel <= iMaxLevel Then
HeadCount = HeadCount + 1
'Add an option button before each paragraph
'Use HeadCount as part of button name
rng.Collapse wdCollapseEnd
rng.Text = String((iLevel - 1) * 4, " ") & _
Format(iLevel) & ") " & para.Range.Text
End If
End If
Next para
End Sub