PDA

View Full Version : Solved: fill feilds in word from excel



SilverSN95
07-28-2009, 06:56 AM
Hello,
Recently I have been working on VBA macro in excel that opens an excel template, and then auto-fills fields in the xls based on what inputs have been entered in the initial excel WB.
Now I would like to do the same thing, except the template is a word file. Is there a way I can create fields or something similar in the word file that will allow me to specify exactly where I want to place what data element?
So basically instead of
dest.Range("A1") = source.Range("B1")
I need
dest.Range("A1") = *something similar in word"

I've looked around for a method of doing this but surprisingly I couldn't find anything useful. Any help is appreciated, thanks.

fumei
07-28-2009, 09:02 AM
Define things a bit more and I am sure you can find something useful. There have been many posts here regarding this type of thing.

Actually, Word has - surprisingly - MORE options for this kind of thing than Excel (IMO).

You could use a formfield.ActiveDocument.Formfields("Here").Result = a string


You could use a bookmark.ActiveDocument.Bookmarks("There").Range.Text = a string


You could use an ASK field (although I am not fond of them).

It all depends on your requirements.

SilverSN95
07-28-2009, 09:26 AM
After playing around a bit it looks like bookmarks will achieve exactly what I would want.
I figured there have been discussions on this before, I just didn't really know what to search for, so thanks for helping.
I'll mark this as solved for now unless I realize I need to be more specific.

fumei
07-28-2009, 10:42 AM
Bookmarks are a very powerful feature in Word. Just to pass along a possible hint.

ActiveDocument.Bookmarks("There").Range.Text = a string
does indeed place the string (whatever it is) at the bookmark. BUT....the above code deletes the bookmark in the process.

Therefore if you require the ability to repeat the process - putting text AT a specified location (a bookmark) - you need to use a procedure that will put the text IN the bookmark and retain the bookmark.

Fortunately, this is not terribly difficult. If it becomes an issue, yes, please post another thread.