We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

VBA search paragraph and extract block of text

allenlo77
allenlo77 asked
on
Medium Priority
838 Views
Last Modified: 2012-05-07
Hello, I am running an Access VBA subroutine that opens a word file, searches the file for some tokens, and extracts those texts until the closing token appears. I am new to word programming but not to excel or access. Anyone have any examples or solutions? Thanks
Comment
Watch Question

Berkson WeinTech Freelancer
CERTIFIED EXPERT

Commented:
Is the start "token" the same as the end token?
Is there more than one set of start and end tokens?
I'll whip up some code, just let me know.  Won't take but a minute.

Author

Commented:
could be, doesnt have to be, your call!
Tech Freelancer
CERTIFIED EXPERT
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview

Author

Commented:
weinberk, I am trying to extract a whole paragraph, wiill this work?

For example, the doc file has this

fdksljfkldjlkj >> hello my name is allen, blah blah

new paragraph blah blah blah

new paragraph blah blah. Okay we are done <<

And I'd like to extract everything between the '>>' token and '<<' token. I am looking at the code you posted and I am not even sure if it will work.
Berkson WeinTech Freelancer
CERTIFIED EXPERT

Commented:
Yes it works.  
I pasted your sample text into a word document then ran the code I provided.  A message box pops up with the text (although boxes appear where carriage returns are since the msg box doesn't support returns like that), and the entire text is available in the variable to do whatever you want with.

Author

Commented:
Ok it works, how do you handle white space between paragraphs? I have 4 paragraphs all separated by white space line.
Berkson WeinTech Freelancer
CERTIFIED EXPERT

Commented:
You just asked to return the text, which is why my code does.  
What is it that you want the code to do with the "white space?"  In your example text, it's just returns.  This might be another topic....

Author

Commented:
well because there is white space between the paragraphs, it gives me an "Invalid procedure call or argument", so I was wondering if you have a solution for that

Author

Commented:
nevermind, it works, the mouse cursor cannot be on the paragraph in between the tokens or else it doesn't work
Berkson WeinTech Freelancer
CERTIFIED EXPERT

Commented:
You're right.  Replace
Selection.Find.ClearFormatting

with
 ActiveDocument.Content.Select
and give it a whirl.  
Please don't forget to accept a solution.  I've worked hard to get a solution for you.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.