Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code to create custom tooltip now prompts me to save...

Status
Not open for further replies.

Tactical

Technical User
Aug 24, 2003
36
0
0
CA
I have a template in my Word Startup folder. Everything works fine but one of the button's tooltip was the macro module's name. Microsoft KB indicates that one can only change the tooltip by using some VBA code as follows:

Sub ChangeToolTip()

With CommandBars("Standard") ' The toolbar (command bar).
With .Controls("My Custom Button") ' The custom control.
.TooltipText = "My Custom Tip" ' The ToolTip
End With
End With

End Sub

I incorporate this code into the template and it does change the tooltip from the module's name to my description. However, now when I exit Word I'm prompted to save the template. Saving does not prevent the "prompt" from coming up on the next instance I load Word.

Can someone tell me what else needs to be done. This wasn't happening before I incorporated the code!

Iris
 
Have you tried to play with the Saved property of the Document object ?
Perhaps like this:
With CommandBars("Standard") ' The toolbar (command bar).
With .Controls("My Custom Button") ' The custom control.
.TooltipText = "My Custom Tip" ' The ToolTip
End With
End With
ThisDocument.Saved = True

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
That's all that was needed.

Thanks

Iris
 
Further to this, I added the command enabled = false. The template that this toolbar is loaded from is a global template and the button in question really only becomes applicable if a user loads a second template. So disabling the button in this fashion makes sense. I then added the code to the other template to enable the button when a user loads it. All good so far. Now, I need the equivalent of the ThisDocument.Saved = true command for when I exit Word as I now get the prompt to save the global template - once again. I've tried some examples through help to no avail.

Iris
 
Thanks for the reply. The template isn't Normal.dot but is a Global template in the startup folder. Nevertheless, I did try that syntax with the template's proper name with out any luck. Any other suggestions?

Iris
 
Hi Iris,

It's quite hard to follow exactly what you're doing with global templates and second templates and ThisDocument, etc., but perhaps this will help.

When you make a toolbar change it will be made in whatever template (or document) your CustomizationContext is set to - and it is this that needs it's Saved property setting.

It would be better if you were more explicit, but you can just do
Code:
CustomizationContext.Saved = True
after making toolbar changes.

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

Professional Office Developers Association
 
Looking at the initial thread in this post, I have a template in Word's startup folder - lets call it "Custom1.dot", that its sole purpose is to provide interaction with an external program via the toolbar that's stored within the template. The toolbar has eight buttons of which one really needs a second template loaded to be functional. Originally, that particular button was seperate from the others and stored in "Custom2.dot". But for aesthetics I thought I would add it to the Custom1 toolbar to keep everything together. I did this and added the code within Custom1 VBA to disable it as follows:

.Enabled = False

Now, when the user loads Word Custom1 toolbar is visible but they see that one of the buttons is disabled. This is a visual clue that they need to load a second template. Without the .Enabled = False I found users clicking the button in question at times forgetting to load Custom2 template - this caused a macro not found error.

Now, in Custom2 I added the code referencing Custom1 toolbar and changed .Enabled = True for the button in question. This works as expected and now the user can click the button.

What I'm finding is that since Custom2 has changed the status of a button in Custom1 Word thinks Custom1 has changed and needs saving. So upon exiting word I get the prompt to save Custom1.

I've tried some various coding including AutoExit, etc. but I still get the prompt. So, I need a code for after Custom2 is loaded and it changes Custom1 tollbar to also tell Word that Custom1 is Saved.

I hope this makes things clearer.

Iris
 
So, I need a code for after Custom2 is loaded and it changes Custom1 tollbar to also tell Word that Custom1 is Saved
Brute force way:
For Each aTemplate In Application.Templates
aTemplate.Saved = True
Next aTemplate


Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 

PH?

That could throw away the user's customizations in Normal which wouldn't be popular.

Iris,

In Custom2.dot, after changing the button state, just add
Code:
Templates("Custom1.dot").Saved = true

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

Professional Office Developers Association
 
I get an error message "The member of the collection does not exist" at the point where Tony's code is inserted.

Iris
 
And this ?
For Each aTemplate In Application.Templates
If UCase(aTemplate.Name) Like "*CUSTOM1*" Then
aTemplate.Saved = True
Exit For
End If
Next aTemplate

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hi PH,

Using your code I incorporated a MsgBox instead of the If .. Then .. Else to see what templates it would display. The only one was the "Custom2.dot" template. I expected to see "Custom1.dot" also. "Custom1.dot" is in Word's startup folder and It loads as evidenced by the toolbar it creates AND I do get a prompt to save it after enabling one of it's custom buttons. So, why do you suppose it it not reflected as one of the names in aTemplate? Do I have to treat templates loaded via startup differently?

Your original code suggestion when I was coding the custom tooltip works. I thought for Custom2.dot it would simply of been a variant of that!

Iris
 
Some further testing with aAddIn instead of aTemplate and the templates name is listed - but still can't mark as SAVED. Any suggestions.

Iris
 
I ended up using the following that works. I was sure that I had tried this and apologize if I posted something that I thought I had tried but perhaps because of a syntax error or something else my post was inaccurate.

Sub AutoNew()

With CommandBars("My Custom Toolbar") ' The toolbar (command bar)
With .Controls("CustomForm.NewMacros.main") ' The custom control
.Enabled = True
End With
End With

For Each aTemplate In Application.Templates
If aTemplate = "Custom1.dot" Then
aTemplate.Saved = True
End If
Next aTemplate

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top