Link to home
Start Free TrialLog in
Avatar of allenlo77
allenlo77

asked on

VBA search paragraph and extract block of text

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
Avatar of Berkson Wein
Berkson Wein
Flag of United States of America image

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.
Avatar of allenlo77
allenlo77

ASKER

could be, doesnt have to be, your call!
ASKER CERTIFIED SOLUTION
Avatar of Berkson Wein
Berkson Wein
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
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.
Ok it works, how do you handle white space between paragraphs? I have 4 paragraphs all separated by white space line.
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....
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
nevermind, it works, the mouse cursor cannot be on the paragraph in between the tokens or else it doesn't work
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.