Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / August 2006

Tip: Looking for answers? Try searching our database.

Auto copying VBA code

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Milo - 15 Aug 2006 16:57 GMT
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
Doug Robbins - Word MVP - 15 Aug 2006 17:43 GMT
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.

Signature

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

>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
[quoted text clipped - 23 lines]
>    ThisDocument.cmdGetNum.Caption = ""
> End Sub
Milo - 15 Aug 2006 17:52 GMT
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

> 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
[quoted text clipped - 6 lines]
> Please reply to the newsgroup unless you wish to avail yourself of my
> services on a paid consulting basis.
Doug Robbins - Word MVP - 15 Aug 2006 20:21 GMT
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.

Signature

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

> Doug,
>
[quoted text clipped - 13 lines]
>> Please reply to the newsgroup unless you wish to avail yourself of my
>> services on a paid consulting basis.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.