Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

INCLUDETEXT 1

Status
Not open for further replies.

cramd

Programmer
Mar 28, 2001
214
US
I'm testing documents with the INCLUDETEXT, I created a "reference.doc" and "letter1.doc". With letter1.doc, I insert file "reference", choose the range of my bookmark and everything works fine. The problem is when I {ctrl} + F9 and type the code that is identical to what is displayed from the previous steps - nothing happens.
Ex: this works--> insert..file(reference)..range(books)..insert link
My document displays "I love books"
Then I toggle my field to get the code and it is:
{INCLUDETEXT "C:\\test\\reference.doc" books}
Next I ctrl+F9 and insert the same text within the brackets and nothing happens. Does anyone know why I am not able to type the code to bring over my text? I have even copied/pasted the code within the brackets and still nothing happens, no errors, no text.
cramd


 
Hi cramd,

I think you probably need to update the field. After entering the text in the field, press F9.

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
Tony,
Oh my "F9" - I've wasted way too much time trying to figure this one out on my on. THANK YOU!! Now, I'm not real clear on the "linking" option. I will be using this in VBA code and that's why I needed to figure this out - if I want the letter to update my reference text, then link would be set to true - correct? In my situation, I never want the text to update my reference document so I either include the switch "\!" or in code set the link to false??
Again, many thanks for the "F9" hint.
cramd
 
Hi cramd,

I don't really follow what you're saying / asking here.

A link will go and pick up the latest version of the text whenever the field is updated (F9 or VBA equivalent).

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
Tony,
My testing is working now, but I need to take this one step further. In my letter document where this is defined {INCLUDETEXT "C:\\test\\reference.doc" books}, I need to change the bookmark "books" to a variable name, somewhat like: {INCLUDETEXT "C:\\test\\reference.doc" library}, library is now a variable that contains the bookmark name "books". I've seen examples that includes a mergefield, such as:
{INCLUDETEXT "C:\\test\\reference.doc" {MERGEFIELD LIBRARY}}, but this document is not a merge document and because of this, I'm not having any luck with the variable working. Without the "mergefield", can I use a variable with the includetext function?
cramd


 
Hi cramd,

You can use a REF field ..
[blue][tt] { INCLUDETEXT "C:\\test\\reference.doc" { REF bookmark_variable } }[/tt][/blue]
where bookmark_variable can contain the name of the bookmark you want to use, but I'm not clear about where or how you're setting the 'variable'.

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
Tony,
I understand what your telling me, but when I try to produce my document, this is what I get:
Error! Bookmark not defined.

On my letter document where I have added this:
{INCLUDETEXT "Z:\\reference.doc" {REF library}}, should I be updating the field? I try, but I get this error:
one or more of the fields could not be updated. Could that be my problem?

Now for a quick run down on the entire process:
I have vba code with the letter document that reads from a table, a field named "library" in the table contains the name of the bookmark that I need inserted in the document. When I run the VBA code with the hard coded bookmark name in the letter document, all is fine ex: {INCLUDETEXT "Z:\\reference.doc" book1 }. Now I need to get over the hurdle to get the letter document to recognize the variable.

I'm not familiar enough with the set & ref keywords, I'll be researching this. Should I be "setting" my variable before referencing it?
Many thanks for your continued interest with my post!

cramd
 
Hi cramd,

I have to be real quick at the moment. How is bookmark "library" defined (assuming it is defined because Word doesn't seem to think so) and how are you trying to set its value?

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
Tony,
"Library" is a field in my table that I read information from, it is not a field that I defined in my MSWORD document. So if I have this statement in my document {INCLUDETEXT "Z:\\reference.doc" {REF library}}, and "library" is a field in my table, but not defined as a field in my MSWORD document that would be my problem - right??

Now, I am trying to define my field "library", stumbling as I go. Am I on the right track, define my field in MSWORD even though the field has been brought into the VBA code with the table information??

cramd
 
Yes, Word Fields reference other Word Fields (Bookmarks etc.) - not VBA variables or table fields (is this coming from Access) - hence my (perhaps not obvious) reference to 'bookmark_variable'.

Try this instead, using Document Variables:

In your doc, have:
[blue][tt] { INCLUDETEXT "C:\\test\\reference.doc" { DOCVARIABLE bookmark_variable } }[/tt][/blue]

and in your code have:
[blue][tt] ActiveDocument.Variables("bookmark_variable"} = Your_VBA_variable[/tt][/blue]

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
Tony,
I am connecting to a DB2 database. After making the changes as you suggested, I'm now getting the full reference.doc inserted into my letter1 document, not just the indicated bookmark. I understand what your doing, I'll continue my testing with this and hopefully will soon have it working.

Many thanks for your help! If you are willing to give me more suggestions, I'm willing to keep trying.....
cramd
 
Hi cramd,

DB2, Access, they're both RDBMS's! It's been a while since I used DB2 but, fortunately, you're not askig about that [smile]

The docvariable is probably empty to start with. After setting it in code you will need to update the field:
Code:
[blue]Activedocument.fields.update[/blue]

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
Tony,
I was out of the office yesterday so didn't get a chance to work on this. This morning, I've been testing and my variable information still does not carry through. I continue to get all the bookmark information, not just the bookmark name from my database. Couple of questions:
Within my code,
1) I open a blank MSWORD document and determine what letter gets inserted into the blank document from information with in the database:
Selection.InsertFile FileName:=pathdoc, Range:=""

Pathdoc contains ex: "(Z:letter/ltr215)"

ltr215 has {includetext "Z:\\reference.doc" {{DOCVARIABLE library \*MERGEFORMAT}}}

I've tried adding your suggested code prior and after the "selection.insertfile" statement, but neither works. I continue to get the entire reference.doc in my active document.
My question is, with this code:
ActiveDocument.Variables("library") = books
(books being a variable from my database that has a value of book1)
ActiveDocument.Fields.Update
If I have this statement prior to the selection.insert etc..., have I lost control of my document variable?
If I run the code after selection.insert..., it seems that the activedocument.fields.update statement would set the variable "library" and all should work.

Any more suggestions??
You've earned your star to get me this far, I just need to get over the hump!!
Many thanks for sticking with me on this one.
cramd
 
Hi cramd,

This is more complicated than I realised, but should still work.

Just to confirm:

- You create a new document
- You include another document in it
- That other document contains the INCLUDETEXT field with the variable bookmark

Code should be along the lines of:
Code:
[blue]Selection.InsertFile FileName:=pathdoc, Range:=""
ActiveDocument.Variables("library") = [red]"[/red]books[red]"[/red]
ActiveDocument.Fields.Update[/blue]

I have just realised as I cut and pasted to write this that you don't have quotes round books - is that just here or in your code too?

You never lose control of your document variable. A variable called "library" exists (perhaps) in your ltr215 source document - it is not copied when you include the file in your new document. You create and set a variable called "library" with your code in your new document - the two variables are different.

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
Tony,
I GOT IT!! It's working.....I was updating in the wrong position!! And...only by a mistake did I catch this....
You have just opened the door for me with several projects!!
I can't THANK YOU enough for not giving up on me!!
I would buy you lunch if you were in Missouri!
Stars are on the way!
cramd
 
My pleasure.

Word Fields are powerful but they are not very user friendly! Glad I could get you on the right road.

'fraid I'm many miles from Missouri, so I'll have to pass on the lunch! Thanks for the star.


Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top