Re: Coding a Macro in Word
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)
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. :)
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.
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. ;)
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
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?
Re: Coding a Macro in Word
No, the button just stays the same, doesn't depress.
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?
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.
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.
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)
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.
Re: Coding a Macro in Word
The button is called TTOnOff
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:
Option Explicit
Public WithEvents oCBTrack As Office.CommandBarButton
Private Sub Document_Open()
Dim oPic As IPictureDisp
'Change to your up image file path
Set oPic = LoadPicture("C:\Cat.bmp", 16, 16)
Set oCBTrack = Application.CommandBars.FindControl(msoControlCustom, "888", "888", True)
If TypeName(oCBTrack) = "Nothing" Then
Set oCBTrack = Application.CommandBars("TrackChanges").Controls.Add(msoControlButton, , , , True) 'Change True to False if you want a permenant button
With oCBTrack
.Enabled = True
.Picture = oPic
.State = msoButtonUp
.Style = msoButtonIcon
.Tag = "888"
.Visible = True
End With
End If
End Sub
Private Sub oCBTrack_Click(ByVal Ctrl As Office.CommandBarButton, CancelDefault As Boolean)
Dim oPic As IPictureDisp
If oCBTrack.State = msoButtonDown Then
oCBTrack.State = msoButtonUp
'Change to your up image file path
Set oPic = LoadPicture("C:\Cat.bmp", 16, 16)
oCBTrack.Picture = oPic
Else
oCBTrack.State = msoButtonDown
'Change to your down image file path
Set oPic = LoadPicture("C:\CatMask.bmp", 16, 16)
oCBTrack.Picture = oPic
End If
End Sub
Meow!
Re: Coding a Macro in Word
Thanks very much
If using this code:
VB Code:
Sub TrackChangesOn()
' TrackChangesOn Macro
' Turns Track Changes On
'
If ActiveDocument.TrackRevisions = True Then
ActiveDocument.TrackRevisions = False
ElseIf ActiveDocument.TrackRevisions = False Then
ActiveDocument.TrackRevisions = True
End If
End Sub
Where would i put it? Sorry my knowledge is very limited in the area, but I'm very greatful for the help.
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:
Private Sub oCBTrack_Click(ByVal Ctrl As Office.CommandBarButton, CancelDefault As Boolean)
Dim oPic As IPictureDisp
If oCBTrack.State = msoButtonDown Then
oCBTrack.State = msoButtonUp
'Change to your up image file path
Set oPic = LoadPicture("C:\Cat.bmp", 16, 16)
oCBTrack.Picture = oPic
If ActiveDocument.TrackRevisions = False Then
ActiveDocument.TrackRevisions = True
End If
Else
oCBTrack.State = msoButtonDown
'Change to your down image file path
Set oPic = LoadPicture("C:\CatMask.bmp", 16, 16)
oCBTrack.Picture = oPic
If ActiveDocument.TrackRevisions = True Then
ActiveDocument.TrackRevisions = False
End If
End If
End Sub
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
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.