New to VBA for Word

C

Chad

Ok I am completely new to VBA for Word so I don't know
difficult or easy it may be for me to accomplish this but
if anyone could help I would really appreciate it.

I want to be able to past a document to a blank word
file, then through a macro or code go through that
document and change its margins. (I know that last part
can be done easily)

I also want the code to look for a key word(s) and if
that word(s) is found to delete that entire line along
with the line below it.

Can this be done?

Thanks,
Chad
 
D

Doug Robbins - Word MVP

Hi Chad,

The following will do what you want.

Dim source As Document, target As Document
Set source = ActiveDocument
Set target = Documents.Add
target.Range.Text = source.Range.Text
target.Activate
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="test", Wrap:=wdFindContinue,
MatchWholeWord:=True, Forward:=True) = True
Selection.Range.Bookmarks("\line").Range.Delete
Selection.Range.Bookmarks("\line").Range.Delete
Loop
End With

I've left the margin thing up to you.

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 
C

Chad

Thanks Doug that did exactly what I needed it to!
-----Original Message-----
Hi Chad,

The following will do what you want.

Dim source As Document, target As Document
Set source = ActiveDocument
Set target = Documents.Add
target.Range.Text = source.Range.Text
target.Activate
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="test", Wrap:=wdFindContinue,
MatchWholeWord:=True, Forward:=True) = True
Selection.Range.Bookmarks("\line").Range.Delete
Selection.Range.Bookmarks("\line").Range.Delete
Loop
End With

I've left the margin thing up to you.

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP



.
 

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