Cannot programmatically insert code on document from form

O

ontheball

I am trying to insert a button onto the document from a click event a button
on a user form. I can do that sucessfully, but I am unable to add the code to
"ThisDocument" to handle the click event of the newly created button. I am
getting an error that says "the object invoked has disconnected from its
clients". This error occurs on the following line:

ActiveDocument.VBProject.VBComponents(1).CodeModule.AddFromString (sCode)

The sCode variable contains another variable sCMDName (txt1.Text). I can
make it work if I leave out the sCMDName and feed the AddFromString method
only string information, but as soon as I add another variable Word give me
the error above and crashes.

Any suggestions would be a help.

Thanks!
 

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