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 / October 2007

Tip: Looking for answers? Try searching our database.

Converting Excel VBA into Word VBA?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
PDF Programmer - 04 Oct 2007 19:21 GMT
I've got the code for an Excel popup utility that adds a date entry
option to the command bar.  I'm trying to figure out how to convert
it
to work within a Word document.  Can anybody help me convert the
code?  Here it is from Excel:

' append the date entry option to the default command bar when
worksheet opens
Private Sub Workbook_Open()
   Dim NewControl As CommandBarControl
' Assign shortcut to display calendar on SHIFT+CTRL+C
   Application.OnKey "+^{C}", "Module1.OpenCalendar"
' Add item to shortcut menu on open
   On Error Resume Next
   Application.CommandBars("Cell").Controls("Insert Date").Delete
   On Error GoTo 0
   Set NewControl = Application.CommandBars("Cell").Controls.Add
   With NewControl
       .Caption = "Insert Date"
       .OnAction = "Module1.OpenCalendar"
       .BeginGroup = True
   End With
End Sub

'remove the date entry option from the default command bar right
before doc closes
Private Sub Workbook_BeforeClose(Cancel As Boolean)
' Delete item from shortcut menu on close
   On Error Resume Next
   Application.CommandBars("Cell").Controls("Insert Date").Delete
End Sub
Jean-Guy Marcil - 05 Oct 2007 04:42 GMT
PDF Programmer was telling us:
PDF Programmer nous racontait que :

> I've got the code for an Excel popup utility that adds a date entry
> option to the command bar.  I'm trying to figure out how to convert
[quoted text clipped - 27 lines]
>    Application.CommandBars("Cell").Controls("Insert Date").Delete
> End Sub

Here is something to get you going.

You may need to add code depending on what you want to happen to the button
you create after the document is closed..

'_______________________________________
Private Sub Document_Open()

Dim NewControl As CommandBarControl

CustomizationContext = ActiveDocument

'Assign shortcut to display calendar on SHIFT+CTRL+C
KeyBindings.Add KeyCategory:=wdKeyCategoryMacro, _
   Command:="Module1.OpenCalendar", _
   KeyCode:=BuildKeyCode(wdKeyShift, wdKeyControl, wdKeyC)

'Add item to shortcut menu on open
On Error Resume Next
Application.CommandBars("Header and Footer").Controls("Date").Delete
On Error GoTo 0
Set NewControl = Application.CommandBars("Header and
Footer").Controls.Add(msoControlButton)
With NewControl
   .Caption = "Insert Date"
   .OnAction = "Module1.OpenCalendar"
   .BeginGroup = True
   'One of those undocumented properties...
   .Style = msoButtonCaption
End With

End Sub
'_______________________________________

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

 
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.