PDA

View Full Version : Solved: text validation in word 2003



suji
12-24-2008, 10:43 PM
Hi,

Merry Christmas to everyone....

Heres the situation.

My word 2003 document has certain value (Model No) on paragraph 2 character 50 to 55 and theres an other value (Versions) on paragraph 3 character 50 to 60.

I would like to validate the value of Versions based on the value of Model number. Every model has a number of versions and the value in para 3 has to be one of the available versions.


This is a system generated word document.


Is it possible to put the available models and versions in a separate excel or access file and then validate from that file.



Eg : Model AAA
Versions : 8/20, 7/16, 6/14, 5/10, 4/8

Model BBB
Versions : 6/14, 5,10, 4/18

Model CCC
Versions : 6/20, 5/18, 4/14, 3/12



Thanks
Suji

lucas
12-26-2008, 12:57 PM
I'm not clear on what you mean by "validate" could you give us some details?

suji
12-26-2008, 11:16 PM
Eg : If the model number in para 2 is AAA then check if the version number in para 3 is one of the approved versions (8/20, 7/16, 6/14, 5/10, 4/8). If version number is not tallying, display a popup with the available versions.

fumei
12-29-2008, 09:55 AM
You could do it in Word by using bookmarks. The string in para 2 is bookmarked, the string in para is bookmarked. It would be very simple to validate between them.

However, that is not what you seem to be asking.

"Is it possible to put the available models and versions in a separate excel or access file and then validate from that file."

This is a different thing all together, and we would need much more detail on what you are doing.

suji
12-29-2008, 11:34 PM
I have attached a sample of the word file that I have to work with and also attached an excel file which has the model numbers (eg AAA, BBB, CCC) and their corresponding version numbers (eg 8/20, 7/22 etc).

I need a macro which will check the model number on para2 and check if the version is one the versions mentioned in the excel sheet.

Thanks
Suji

suji
12-29-2008, 11:36 PM
sample excel file attached here

fumei
12-30-2008, 11:30 AM
You give us two files, but there is no code at all. What have you actually tried?

You could do it, "validating" from the Excel file. However, depending on the amount (volume) of data elements involved, frankly, I would not. If it is small enough - and certainly the examples you give are small enough - you could do it just in Word.

I would like to point out:

"My word 2003 document has certain value (Model No) on paragraph 2 character 50 to 55 and theres an other value (Versions) on paragraph 3 character 50 to 60. "

No...those number are incorrect. The Model value - "AAA" - in paragraph 2 starts at document character count 26. The Version value - 08/20 - in paragraph 3 starts at document character count 40. Those paragraphs do NOT (unlike the other paragraphs) have spaces, they have Tabs, and Tabs count as one character.

Where did you get your character 50 to 55 from?

In fact, if you actually check....
MsgBox ActiveDocument.Paragraphs(2).Range.Characters.Count
you get a return of 13. There are only 13 characters in paragraph 2. Which makes it very hard to get character 50 to 55.

Further, paragraph 3 has a Tab after the text you wish to validate. This can complicate things, unless this will ALWAYS be an artifact of the generated text file. If it always has a tab there, fine, no problem, you can strip it off to get the text.

Of course you can also test to se if there is a tab, or not. As i have mentioned many times, this is not difficult, it is again, only logic. But you have to know what the logic is. Something like:

1. get text of paragraph 3
2. strip off the paragraph mark
3. check if last character is a Tab
4. if it is a Tab, strip it off and use last 4 characters. If not, then use last four characters.

I would further like to point out that you have a difference in values that would have to be dealt with.

In the document, for example, you have a Version number of 08/20. However, in the Excel file you have 8/20. Do you grab the FIVE characters in the document (08/20)? You probably should, because what if it was 12/20 - or whatever. After looking at the Excel file, there are no two digits (AAA = 8/20, 7/22, 6/26, 5/28, 4/32, 3/34, 2/38). If so...there is a conflict with the document that DOES have two characters - 08/20)

In any case, fussing with this CAN be done in Word. I am attaching three word documents in a ZIP file.

sample_Gerry.doc
sample_Gerry_B.doc
sample_Gerry_Blah.doc

I put code into the Document_Open event for all three.

sample_Gerry.doc
sample_Gerry_B.doc

should both display a message (when you open the file) stating the Model has a valid Version number.

sample_Gerry_Blah.doc has a deliberate error - the Version number is NOT valid. Opening the file will display a message stating this.

suji
12-31-2008, 07:02 AM
Sorry for the discrepancies in the sample document. My questions were actually based on data from the original document but I had to make some changes to them since it had some company data which I was not sure whether I could post on the net.

Anyhow you managed to produce exactly what I wanted. Thank you.

Also just curious to know how this can be done if the models data were in excel.

suji
01-03-2009, 12:19 PM
Fumei,

Appreciate if u show me how this can done if the models data were in excel.

Thanks

fumei
01-06-2009, 10:30 AM
What have you tried?

What have you searched for? This is a common enough request.