S
steve321
I hate to ask these really simple questions because I don't want to be a
'ninny' and waste people's time--nevertheless I've been stumped on this one
for a while, sooo ...
My goal is to come up with a generic Word doc that is a report template. My
master template has all the possible 'subcomponents' I might need, so I just
cull out the sections that don't apply for the report of a given project. My
thought is to have a form with checkboxes for each subcomponent--so I can
place a check for the subcomponents I want to keep, and the rest will be
purged.
At this point in my project I'm JUST trying to get my code to recognize a
particular sentence. (Later there will be sentences such as "Section A
begins." And "Section A ends." Then I can assign those to variables and cull
with IN THEN statements--hopfully.) Anyway ...
Given a Word doc (that is open the whole time) that has the text
“Steve’s VBA practice 3-31-07.
Section One.
Section Two.
Section Three.â€
(Without the quotes.) And given a form with a button called “cmdTRUNCATEâ€
and the following code:
Private Sub cmdTRUNCATE_Click()
' If ActiveDocument.Paragraphs = "Section One." Then
' If CheckBox1.Value = True Then
' ActiveDocument.Paragraphs = Delete
' End If
' End If
If ActiveDocument.Sentences.Item = "Section One." Then
MsgBox "yes"
Else: MsgBox "NOâ€
End If
End Sub
Neither of these (or several others) worked… The compiler Errors on my
Object with "Item is not optional." My guess is that I identify the
appropriate Object, such as “Paragraphs†or “Sentences†then compare it’s
appropriate Property to the string “Section One.†But for this scenario,
what is the correct Object and Properties?? Or am I even on the right
track???
Thanks in advance for any ideas ) -steve
'ninny' and waste people's time--nevertheless I've been stumped on this one
for a while, sooo ...
My goal is to come up with a generic Word doc that is a report template. My
master template has all the possible 'subcomponents' I might need, so I just
cull out the sections that don't apply for the report of a given project. My
thought is to have a form with checkboxes for each subcomponent--so I can
place a check for the subcomponents I want to keep, and the rest will be
purged.
At this point in my project I'm JUST trying to get my code to recognize a
particular sentence. (Later there will be sentences such as "Section A
begins." And "Section A ends." Then I can assign those to variables and cull
with IN THEN statements--hopfully.) Anyway ...
Given a Word doc (that is open the whole time) that has the text
“Steve’s VBA practice 3-31-07.
Section One.
Section Two.
Section Three.â€
(Without the quotes.) And given a form with a button called “cmdTRUNCATEâ€
and the following code:
Private Sub cmdTRUNCATE_Click()
' If ActiveDocument.Paragraphs = "Section One." Then
' If CheckBox1.Value = True Then
' ActiveDocument.Paragraphs = Delete
' End If
' End If
If ActiveDocument.Sentences.Item = "Section One." Then
MsgBox "yes"
Else: MsgBox "NOâ€
End If
End Sub
Neither of these (or several others) worked… The compiler Errors on my
Object with "Item is not optional." My guess is that I identify the
appropriate Object, such as “Paragraphs†or “Sentences†then compare it’s
appropriate Property to the string “Section One.†But for this scenario,
what is the correct Object and Properties?? Or am I even on the right
track???
Thanks in advance for any ideas ) -steve