Auto copying VBA code

M

Milo

I have a document that contains a button that the VBA code goes out to
a database and collects a unique number. Then it returns the number to
the document as a unique ID.

I am having an issue that when I copy the button over to a new document
that the VBA code is not being carried over. Is there a way to
automatically set this up to copy the code from one document to another
as I copy over the button?

My code is as follows:
Private Sub cmdGetNum_Click()
Dim oWebService As clsws_GetNum
Dim ctl As Control

Set oWebService = New clsws_GetNum
Dim strResult As String
strResult = oWebService.wsm_GetDocumentID("DM-1040E")

ThisDocument.txtSerialNumber = strResult
'ActiveDocument.Shapes(1).Visible = msoFalse
ThisDocument.cmdGetNum.Locked = True
ThisDocument.cmdGetNum.Enabled = False
ThisDocument.cmdGetNum.BackColor = &HFFFFFF
ThisDocument.cmdGetNum.ForeColor = &HFFFFFF
ThisDocument.cmdGetNum.BackStyle = fmBackStyleTransparent
ThisDocument.cmdGetNum.Caption = ""
End Sub
 
D

Doug Robbins - Word MVP

It would be better to have this document set up as a template and for the
code to be run by an autonew macro in the template. Then it would run
whenever a new document is created from the template without the need for
the user to click on any buttons.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
M

Milo

Doug,

Thanks for the idea, unfortunately the documents that I am copying into
are all ready created, so no new documents would be created for this.

Thanks
 
D

Doug Robbins - Word MVP

Well in that case, I would have the code in an Add-in and a button on the
toolbar to be used for the purpose.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

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