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
ASKER
could be, doesnt have to be, your call!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
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.
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.
ASKER
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....
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....
ASKER
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
ASKER
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.ClearFormat ting
with
ActiveDocument.Content.Sel ect
and give it a whirl.
Please don't forget to accept a solution. I've worked hard to get a solution for you.
Selection.Find.ClearFormat
with
ActiveDocument.Content.Sel
and give it a whirl.
Please don't forget to accept a solution. I've worked hard to get a solution for you.
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.