PDA

View Full Version : Theme change tracking



Macht59
12-15-2010, 08:55 AM
Hello.

I heed to write macros that makes pop-up "Theme is changed." when user change theme in MS Word.

fumei
12-15-2010, 11:26 AM
Why? If they have actually changed it, do they not know what they did?

Macht59
12-15-2010, 11:39 AM
Why? If they have actually changed it, do they not know what they did?

My macros is much bigger. It will not only say "Theme is changed."
I do not knew how to track when theme was changed.

fumei
12-15-2010, 12:05 PM
Which does not answer my question whatsoever. I understand you do not know how to track when the theme is changed. That is why you posted.

And...I asked why. However, to answer, if you are talking about a real-time detection - that is, they change the theme and something goes DING!, the theme has changed...then, no.

All you can do it detect what theme is there, and at some point take another look. If it is changed then...it is changed.

If it is not changed...then it is not changed. But I still would like to know why you want to know, AND why you want to give a message.

I can sort of understand why you may want to know, but again, if they change it, do they not know they changed it? After all, it is not something that can easily be "accidentally" changed.

In any case, if you REALLY want to have something to check:

ActiveDocument.ActiveThemeDisplayName

returns the DisplayName. Note this is NOT - repeat NOT - the value that is required to change the theme programmatically.

Say you have Bold Stripes (although why I have no idea why as I think using themes is horrible).

ActiveThemeDisplayName = "Bold Stripes"

However, if you use that to programmatically make it Bold Stripes, it will fail. The proper syntax is:

ActiveDocument.ApplyTheme Name:="boldstri 011"

The same applies to making the theme "none".

You can use ActiveThemeDisplayName to get "none", but you can not use "none" to apply , well, none.

You need to use ActiveDocument.RemoveTheme

So, you could use:

ActiveDocument.Variables("CurrentTheme").Result = _
ActiveThemeDisplayName
to store the current them name in a variable. Say at document open??

Then you could at some time test against it.

' the current theme
If ActiveDcoument.ActiveThemeDisplayName <> _
ActiveDocument.Variables("CurrentTheme").Result Then
MsgBox "HEY! You changed the theme. Did you know you changed " _
"the theme? Just checking, in case you did not know what you have done."
End If


But again, as a real-time they just changed it, and now I am going to tell them they have - No.

And again, tell me me why you want to know this????

fumei
12-15-2010, 12:10 PM
Bottom line. You can not "track" when the theme is changed. You can test if it HAS changed, if you store the name of the theme, and then, at some later time, test to see if the current theme is the same as what you stored.

Macht59
12-15-2010, 02:15 PM
And again, tell me me why you want to know this????
:think:
I am studing at university and I have a course of VBA. And this is my home task to write macro on VBA.
This is text of my task:

Create a macro that when you change the color theme of the document allows the user to set the color used in styles, ie do not change color automatically when you change the color theme. (translated with Google)

P.S. My English is bad. Its really hard to read and write here but I'll never give up :)

Macht59
12-15-2010, 02:18 PM
Is that right?
Sub AutoOpen()
If ActiveDcoument.ActiveThemeDisplayName <> _
ActiveDocument.Variables("CurrentTheme").Result Then
MsgBox "HEY! You changed the theme. Did you know you changed " _
"the theme? Just checking, in case you did not know what you have done."
End If
End Sub

fumei
12-15-2010, 02:55 PM
What do you mean, is that right? Is it correct coding? Yes. But it requires that a DOCVARIABLE named "CurrentTheme" has been previous set.

So IF the current theme name (ActiveThemeDisplayName) is NOT EQUAL TO (<>) the value stored in the DOCVariable CurrentTheme THEN display the messagebox.

BTW: we do not generally help people with school assignments.

Macht59
12-15-2010, 03:09 PM
It works.
Thank you for your help.