PDA

View Full Version : reading saved word documents



phill952000
12-18-2008, 02:49 AM
hi,

i am wondering if it is possible to read the name of the most recently saved word file in a certain folder and increment it and apply the info to a text field in a newly opened word document.

i will elaborate.

what i have is a macro that, when the macro button is clicked, takes the information from form fields in a word document and stores each form field data into a different variable. within the same process the variables are used as the document save name.

now.

the first form field i have in my word document is a number that needs to increment by 1 each time i save a new document. therefore i have to check the previous number of the previous saved document so that i can enter the correct number into the new document.

i am wondering if there is any way that i could add some code to my existing macro that, when a new document is opened, can read the first form field of the previous saved document and apply the incremented number into the first form field of the new document.

i hope this makes sense.

if not please ask and i will clarify any issues.

regards

phill952000

fumei
12-18-2008, 12:54 PM
"that needs to increment by 1 each time i save a new document. "

and

"when a new document is opened"


Please explain the context of "new document". Are you using a template?

"the first form field i have in my word document is a number that needs to increment by 1"

Formfields are used for user input. That does not sounds like user input. What if YOUR number is 5...and the user changes it to 17? Or changes it to "I don't give a crap".

It sounds like a text formfield, so "I don't give a crap." is a valid value!

There are a number of ways to do what I think you are trying to do.

One way would be to store the incrementing number in a wee text file. Each time you do whatever it is you are doing, open the wee text file and increment the number. Plus take the number and put it in your "new" document.

Can you "if it is possible to read the name of the most recently saved word file in a certain folder and increment it"

Well...sort of. Yes, you can read the name of the most ercently saved word file in a certain folder. But "increment" it? The name is a string. You can not increment a string. You can append another string to it. You can extract a string out of it (the name) and look at that extracted string as a number, and increment THAT.

phill952000
12-19-2008, 01:05 AM
"that needs to increment by 1 each time i save a new document. "

and

"when a new document is opened"


Please explain the context of "new document". Are you using a template?

"the first form field i have in my word document is a number that needs to increment by 1"

Formfields are used for user input. That does not sounds like user input. What if YOUR number is 5...and the user changes it to 17? Or changes it to "I don't give a crap".

It sounds like a text formfield, so "I don't give a crap." is a valid value!

There are a number of ways to do what I think you are trying to do.

One way would be to store the incrementing number in a wee text file. Each time you do whatever it is you are doing, open the wee text file and increment the number. Plus take the number and put it in your "new" document.

Can you "if it is possible to read the name of the most recently saved word file in a certain folder and increment it"

Well...sort of. Yes, you can read the name of the most ercently saved word file in a certain folder. But "increment" it? The name is a string. You can not increment a string. You can append another string to it. You can extract a string out of it (the name) and look at that extracted string as a number, and increment THAT.

phill952000
12-19-2008, 01:06 AM
hi, thanks for the reply,

i think i know what you are saying and i will give it a go.

i will get back in touch as to whether i am succesfull or need sum more guidance.

regards

phill952000

fumei
12-22-2008, 01:22 PM
The most important question (unanswered) is whether you are doing this from a template...or not.