beginner Q: Assessing the text in a sentence...

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 :eek:) -steve
 
H

Helmut Weber

Hi Steve,

set up a userform. How?
see: http://word.mvps.org/FAQs/Userforms/CreateAUserForm.htm

Organize your doc, so that
Section One., Section Two., Section Three.
are formatted in a heading style.

Put a listbox on your userform.
Populate the listbox with the text from
the paragraphs of heading style.

Make sure, the listbox's multiselect property
is "1 - fmmultiselectmulti".

Select from the listbox the so called sections to be deleted.
The are probably no sections in Word's terminology.

Learn how to process all selected items in a multiselect listbox.
http://word.mvps.org/faqs/userforms/GetMultiSelectValues.htm

Google here for bookmarks("\headinglevel")
or see the posting "Heading" above.

Search for "Section One." e.g. in a paragrph of your heading style.
Select it. Might work without selecting as well. (?)
Delete the selection.range.bookmarks("\headinglevel").range

It ain't that easy.

E.g.
Private Sub cmdTRUNCATE_Click()

' If ActiveDocument.Paragraphs = "Section One." Then
If activedocument.paragraphs(1).range.text = "Section One." & chr(13)
' If CheckBox1.Value = True Then
' ActiveDocument.Paragraphs = Delete ActiveDocument.Paragraphs(1).range.Delete
' End If
' End If

Forget about sentences.

Impossible to teach VBA in 50 lines.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top