vb code works fine if i open .dot file but not working in doc file

C

cgijag

Hello,
i've created a .dot file containing vb code that copies info from one active
x text box to a text box on other pages. It works great if you open the .dot
file itself. If you double click on the .dot file so it opens a new .doc
file the vb code is not copying the info. If i bring up vb mode, the code is
stil listed for that field. anyone ever run into this problem? Thank you.
 
G

Gordon Bentley-Mix

Please post your code.
--
Cheers!

Gordon Bentley-Mix
Word MVP

Uninvited email contact will be marked as SPAM and ignored. Please post all
follow-ups to the newsgroup.
 
C

cgijag

Here is the code. Sorry, I should have posted it originally.

Private Sub TextBox21_Change()
ThisDocument.TextBox2113.Value = ThisDocument.TextBox21.Value
ThisDocument.TextBox213.Value = ThisDocument.TextBox21.Value
ThisDocument.TextBox2131.Value = ThisDocument.TextBox21.Value
ThisDocument.TextBox2132.Value = ThisDocument.TextBox21.Value
ThisDocument.TextBox2133.Value = ThisDocument.TextBox21.Value
ThisDocument.TextBox2134.Value = ThisDocument.TextBox21.Value
End Sub
 
C

cgijag

I've made an odd discovery. If i make a copy of the .doc file i'm using and
rename it as a .dot file (i know, its a no-no to do that) my vb works. If i
open the .doc and save as a template my vb doesn't work. weird.
 
J

Jonathan West

cgijag said:
Here is the code. Sorry, I should have posted it originally.

Private Sub TextBox21_Change()
ThisDocument.TextBox2113.Value = ThisDocument.TextBox21.Value
ThisDocument.TextBox213.Value = ThisDocument.TextBox21.Value
ThisDocument.TextBox2131.Value = ThisDocument.TextBox21.Value
ThisDocument.TextBox2132.Value = ThisDocument.TextBox21.Value
ThisDocument.TextBox2133.Value = ThisDocument.TextBox21.Value
ThisDocument.TextBox2134.Value = ThisDocument.TextBox21.Value
End Sub

Change "ThisDocument" to "ActiveDocument" thoughout your code.

ThisDocument refers to the document or template that contains the code.
ActiveDocument refers to the document open for editing. When you have the
template itself open for editing, both are the same. When you create a
document based on your template, the code is trying to change the template,
not the document, and because the template it not open for editing, it
fails.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top