|
-
Dec 20th, 2006, 05:27 PM
#1
Thread Starter
Addicted Member
[RESOLVED] Need help working with MS Word docs
I'd like to make some sort of parser, but I'm a bit lost.
I'd like to format a Word file, so I add to it variables like $NAME$, $ADDRESS$, etc and then I swap those variables with values from a database.
So far I've figured out how to find text in textboxes, tables, and the document itself (although Word format the variables so they are 3 different words, but that's not a problem), however I'm lost now... how can I change those variables? which functions or methods do I need to use???
-
Dec 20th, 2006, 05:55 PM
#2
Hyperactive Member
Re: Need help working with MS Word docs
 Originally Posted by Neverbirth
... how can I change those variables? which functions or methods do I need to use???
Do you mean: ?
-
Dec 20th, 2006, 06:11 PM
#3
Thread Starter
Addicted Member
Re: Need help working with MS Word docs
 Originally Posted by Ember
No, I mean having a document with special words, for example:
" Hello Mr./Mrs. $NAME$:
Nowadays...."
And then replace those special words with data taken from a database. I've already worked out a system to parse these words, but it's rather bad... and I bet people here with more knowledge using MS Word can give me some hints...
-
Dec 20th, 2006, 06:31 PM
#4
Hyperactive Member
Re: Need help working with MS Word docs
That I do not know. Sorry.
How to recognise a name?
If "Hello Dear Old Friend"?
-
Dec 20th, 2006, 06:32 PM
#5
Re: Need help working with MS Word docs
That's a mail merge.. Word already has the feature, so you may as well just utilise that.
I think there's an article about that in the FAQ's of this forum.
-
Dec 20th, 2006, 06:59 PM
#6
Thread Starter
Addicted Member
Re: Need help working with MS Word docs
 Originally Posted by si_the_geek
That's a mail merge.. Word already has the feature, so you may as well just utilise that.
I think there's an article about that in the FAQ's of this forum.
But that article doesn't seem to show how to make use of it along with VB, also, that feature isn't available on Word 2000, is it? I need to support that version as well, since most computers around here are old and still use it.
-
Dec 21st, 2006, 05:06 PM
#7
Re: Need help working with MS Word docs
As far as I know, mail merge has been in it for many years (not sure how long, but I'm pretty sure it was in 97).
Like with virtually any actions you can do in Word, you can write code to automate it too.. one of the easiest ways is to record a macro (of you doing what you want manually) then copy it to your VB program - with only a few changes.
I'm afraid I haven't got time to make an example, but I think that the other articles about Word in the FAQ's should be enough for you to at least make a decent start.. we should then be able to help you correct/expand what you have done.
-
Dec 21st, 2006, 06:44 PM
#8
Thread Starter
Addicted Member
Re: Need help working with MS Word docs
 Originally Posted by si_the_geek
As far as I know, mail merge has been in it for many years (not sure how long, but I'm pretty sure it was in 97).
You are right, since I never used it, and its translation to my language isn't exactly what I'd have chosen I missed it.
I'm afraid to say that I don't have too much time to experiment with this (in fact, today "is my limit" of looking at it). Dunno, just wanted some samples or advices on how to do this, and it seems the mailmerge function makes use of a lot of things, so I'll stick with my simple method for now, and I'll try to learn about mailmerge automation later when I have a lot more time...
Last edited by Neverbirth; Dec 21st, 2006 at 06:47 PM.
-
Dec 22nd, 2006, 04:28 AM
#9
Re: Need help working with MS Word docs
you can use Words fnd and replace to do what you want, or you can use the vb replace function
mailmerge has been there since there was Word
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Dec 22nd, 2006, 10:01 AM
#10
Thread Starter
Addicted Member
Re: Need help working with MS Word docs
 Originally Posted by westconn1
you can use Words fnd and replace to do what you want, or you can use the vb replace function
I didn't think of the replace function, and I didn't know of the find function, so far what I was doing was a for loop through all the Words items, so as you can guess it required a lot of power and time.
Thank you.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|