Results 1 to 20 of 20

Thread: Coding a Macro in Word

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2006
    Posts
    10

    Coding a Macro in Word

    Hi All,

    I have made buttons in word using VB code that turn on/off track changes, print track changes, or show track changes on screen.

    What I'm trying to figure out now is how I can change the image on the button using VBCode. What is the button's image property, and how would I go about assigning it an image using a VB macro?

    Thanks,
    Mathew

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Coding a Macro in Word

    Is this VB6 or Word VBA?

  3. #3

    Thread Starter
    New Member
    Join Date
    Jun 2006
    Posts
    10

    Re: Coding a Macro in Word

    Under the about is says Microsoft Visual basic 6.3, however, i am accessing it through word (click visual basic editor)

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Coding a Macro in Word

    Yes, its VBA.

    Is this a button from the Controls Toolbox or from the Forms toolbox?

    Moved

    Edit: too late. Hack is just way too fast lol.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    New Member
    Join Date
    Jun 2006
    Posts
    10

    Re: Coding a Macro in Word

    Its not from the toolbox, its a button made on the toolbar in word (i.e. drag and drop a macro onto the toolbar)... I assigned the button an image, and I need the image to change when i click the button.

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Coding a Macro in Word

    You mean like you want to create a down image and an up image?
    Your button is a CommandBarButton type.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  7. #7

    Thread Starter
    New Member
    Join Date
    Jun 2006
    Posts
    10

    Re: Coding a Macro in Word

    So when track changes are on, i want the image to be say a check mark, and when they're off, i want the image to be an X. So just switching the button image... I know how to do it in word, but i dont know the code for it.

    Thanks

  8. #8
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Coding a Macro in Word

    Is it a regular type of commandbar button or is it a toggle button? Their is only a _CLick event for a commamnd bar button so its not possible for that type. When you click it does the button stay depressed until you click it again?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  9. #9

    Thread Starter
    New Member
    Join Date
    Jun 2006
    Posts
    10

    Re: Coding a Macro in Word

    No, the button just stays the same, doesn't depress.

  10. #10
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Coding a Macro in Word

    Then you will need to keep track of each button click and change it every other time for one image and the rest get the other image.

    Which toolbar is your button on?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  11. #11

    Thread Starter
    New Member
    Join Date
    Jun 2006
    Posts
    10

    Re: Coding a Macro in Word

    its on my own toolbar "TrackChanges"... how would I code something like that. Like on click 1 do this, click 2 etc.

  12. #12
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Coding a Macro in Word

    Left click at the end of the toolbar its on and when you get the popup menu "Add or Remove Buttons" what is the submenu showing? It should show the menu name and the next item will be Customize.

    You do know there is a Reveiwing toolbar that has a button to turn on and off the track changes.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  13. #13

    Thread Starter
    New Member
    Join Date
    Jun 2006
    Posts
    10

    Re: Coding a Macro in Word

    I realize that the track changes button is there, it is mainly for the other buttons. There is no place to left click at the end of my toolbar (i know what you're referring to, but i dont have that little arrow)

  14. #14
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Coding a Macro in Word

    Ok, so you created a New toolbar called "TrackChanges" correct? On this toolbar the button is called?

    I'm writting a small example for you.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  15. #15

    Thread Starter
    New Member
    Join Date
    Jun 2006
    Posts
    10

    Re: Coding a Macro in Word

    The button is called TTOnOff

  16. #16
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Coding a Macro in Word

    Ok, here we go. I created a new temporary button for my Reveiwing toolbar. I added a toggle feature so when its in one state its selected and when in another state its not selected. You will have changing images, one for each state change.

    Just change the images your using and you should be ok.

    VB Code:
    1. Option Explicit
    2.  
    3. Public WithEvents oCBTrack As Office.CommandBarButton
    4.  
    5. Private Sub Document_Open()
    6.     Dim oPic As IPictureDisp
    7.     'Change to your up image file path
    8.     Set oPic = LoadPicture("C:\Cat.bmp", 16, 16)
    9.     Set oCBTrack = Application.CommandBars.FindControl(msoControlCustom, "888", "888", True)
    10.     If TypeName(oCBTrack) = "Nothing" Then
    11.         Set oCBTrack = Application.CommandBars("TrackChanges").Controls.Add(msoControlButton, , , , True) 'Change True to False if you want a permenant button
    12.         With oCBTrack
    13.             .Enabled = True
    14.             .Picture = oPic
    15.             .State = msoButtonUp
    16.             .Style = msoButtonIcon
    17.             .Tag = "888"
    18.             .Visible = True
    19.         End With
    20.     End If
    21. End Sub
    22.  
    23. Private Sub oCBTrack_Click(ByVal Ctrl As Office.CommandBarButton, CancelDefault As Boolean)
    24.     Dim oPic As IPictureDisp
    25.     If oCBTrack.State = msoButtonDown Then
    26.         oCBTrack.State = msoButtonUp
    27.         'Change to your up image file path
    28.         Set oPic = LoadPicture("C:\Cat.bmp", 16, 16)
    29.         oCBTrack.Picture = oPic
    30.     Else
    31.         oCBTrack.State = msoButtonDown
    32.         'Change to your down image file path
    33.         Set oPic = LoadPicture("C:\CatMask.bmp", 16, 16)
    34.         oCBTrack.Picture = oPic
    35.     End If
    36. End Sub
    Meow!
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  17. #17

    Thread Starter
    New Member
    Join Date
    Jun 2006
    Posts
    10

    Re: Coding a Macro in Word

    Thanks very much

    If using this code:

    VB Code:
    1. Sub TrackChangesOn()
    2.  
    3.  
    4. ' TrackChangesOn Macro
    5. ' Turns Track Changes On
    6. '
    7. If ActiveDocument.TrackRevisions = True Then
    8.     ActiveDocument.TrackRevisions = False
    9. ElseIf ActiveDocument.TrackRevisions = False Then
    10.     ActiveDocument.TrackRevisions = True
    11. End If
    12.  
    13. End Sub

    Where would i put it? Sorry my knowledge is very limited in the area, but I'm very greatful for the help.

  18. #18
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Coding a Macro in Word

    Np, you would place it in the _Click event. Then depending on which state you want to represent on and off you would place it accordingly.

    VB Code:
    1. Private Sub oCBTrack_Click(ByVal Ctrl As Office.CommandBarButton, CancelDefault As Boolean)
    2.     Dim oPic As IPictureDisp
    3.     If oCBTrack.State = msoButtonDown Then
    4.         oCBTrack.State = msoButtonUp
    5.         'Change to your up image file path
    6.         Set oPic = LoadPicture("C:\Cat.bmp", 16, 16)
    7.         oCBTrack.Picture = oPic
    8.         If ActiveDocument.TrackRevisions = False Then
    9.             ActiveDocument.TrackRevisions = True
    10.         End If
    11.     Else
    12.         oCBTrack.State = msoButtonDown
    13.         'Change to your down image file path
    14.         Set oPic = LoadPicture("C:\CatMask.bmp", 16, 16)
    15.         oCBTrack.Picture = oPic
    16.         If ActiveDocument.TrackRevisions = True Then
    17.             ActiveDocument.TrackRevisions = False
    18.         End If
    19.     End If
    20. End Sub
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  19. #19

    Thread Starter
    New Member
    Join Date
    Jun 2006
    Posts
    10

    Re: Coding a Macro in Word

    Thank you very much for the help, but since this is being used over a network, people will not have common access to any images. Is there any way to get around this problem (perhaps by embedding the picture)? Also, how do I tell the program to shade the button when track changes are on. I.e.

    If ActiveDocument.TrackRevisions = True Then
    (I want it to make the button depressed here)

    Thanks so much,
    Mathew

  20. #20
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Coding a Macro in Word

    Its the msoButtonUp and msoButtonDown that I have provide in the previous posts code example. The only thing left to fix is the common access to the image.

    If you change the path to a network link that should solve it.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width