vba script to remove specific text from a word2000 doc

F

Frank

I would like to creat a macro using vba script to remove specific text from a
word2000 document.
Appreciate your help
 
J

Jonathan West

Frank said:
I would like to creat a macro using vba script to remove specific text from
a
word2000 document.
Appreciate your help

It's impossible to help unless you are able to provide some sort of
description about how to identify the text that needs to be removed.

--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
F

Frank

The text can change. Is it possible to use a section break or like excel a
named range to identify the text that should be removed
 
J

Jonathan West

Frank said:
The text can change. Is it possible to use a section break or like excel a
named range to identify the text that should be removed


OK, but how do you intend to identify the text that you need to delete at
any particular time? Is this something that can be identified from the
structure of the document, or do you want to delete every occurrence in the
document of the currently selected text? What are the rules for working out
what should go?


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
J

Jonathan West

Frank said:
Simply delete every thing in the specific section.


Do you mean between two section breaks? Are the section breaks there
already? Is it the first, second section of the document, or which?

I really do want to help, but getting information out of you is like getting
blood out of a stone!


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
F

Frank

lol. Sorry about the confusion. It makes no difference what sections.
Section1 and section 2 Between Section 10 and 11. Dont care. Once I know how
to do it I will simple enter the propper section Info. I would like to delete
text that can vary in content, but is always All the text between lets say
Section1 and 2 .
 
T

Tony Jollans

I'm as confused as Jonathan. Do you have a document with text you want to
delete? Or are you planning on writing one (which rather begs the question)?

If the text to be deleted is not already identifiable (other than manually)
you are going to have to mark it somehow and a bookmark is (roughly)
equivalent to a named range in Excel. I wouldn't personally use sections for
this unless they are already there - deleting entire sections can have
effects on formatting unless you are very careful.
 
J

Jonathan West

Frank said:
lol. Sorry about the confusion. It makes no difference what sections.
Section1 and section 2 Between Section 10 and 11. Dont care. Once I know
how
to do it I will simple enter the propper section Info. I would like to
delete
text that can vary in content, but is always All the text between lets say
Section1 and 2 .


Ah OK. This will do the needful.

ActiveDocument.Sections(n).Range.Delete

where n is the number of the section you want removed.

If you want to retain the section break at the end of the section, and just
remove all the content between two section breaks, do this.

Dim oRange as Range
Set oRange = ActiveDocument.Sections(n).Range
oRange.MoveEnd Unit:=wdCharacter, Count:=-1
oRange.Delete


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 

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