Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #4  
Old 11-06-2014, 01:52 PM
macropod's Avatar
macropod macropod is offline Creating Event Handlers Programmatically Windows 7 64bit Creating Event Handlers Programmatically Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

To programmatically add code to a Word document or template requires the basic process as for Excel, etc.:
1. Set a reference to Microsoft Visual Basic For Applications Extensibility.
2. Give trusted access to the VBE.

The Excel procedure below will add a new module named "NewModule" to ThisWorkbook:
Code:
Sub AddModule()
Dim VBComp As VBComponent
Set VBComp = ThisWorkbook.VBProject.VBComponents.Add(vbext_ct_StdModule)
VBComp.Name = "NewModule"
Application.Visible = True
End Sub
The Word equivalent is:
Code:
Sub AddModule()
Dim VBComp As VBComponent
Set VBComp = ThisDocument.VBProject.VBComponents.Add(vbext_ct_StdModule)
VBComp.Name = "NewModule"
Application.Visible = True
End Sub
If this isn't the kind of thing you need, you need to say what it is you do need.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
 

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating Event Handlers Programmatically Adding macro to normal.dotm programmatically etippelt Word VBA 6 04-08-2013 05:55 PM
Programmatically convert Office documents to PDF from C# hemaneelagiri Office 0 10-21-2011 06:07 AM
outlook programmatically read an attachment into byte array chriskaza81 Outlook 0 11-19-2010 01:03 AM
Programmatically get File Path for currently opened WORD document franferns Word 1 11-26-2009 12:36 PM
Programmatically changing folder item selection Richard Cook Outlook 0 02-09-2007 02:25 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:18 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft