PDA

View Full Version : Solved: VBA code to select a specific tab



evamads
07-21-2008, 07:38 AM
Hi,

A 3rd-party program is using the Mail Merge to merge data into a Word-document. When this is done, Word is showing the document with the Mailings-tab.

I would like Word to show the Home-tab - as the Mail Merge is over and done at this time.

I have tried this:
<tab idMso="TabMailings" getVisible="rxtabMsoMailings_GetVisible"/>

and the VBA:
Sub rxtabMsoMailings_GetVisible(control As IRibbonControl, ByRef returnedVal)
returnedVal=False
End sub

But this will hide the Mailings-tab. Does anyone know if there is a "getSelected" argument or another way to select the Home-tab?

Thanks

Eva

drichird
08-12-2008, 12:32 AM
I also have had a need to control tab focus in a Word 2007 VBA application. It appears there is no actual command to do this, from what I have researched. I have tried to use (from inside a VBA macro) the command: sendkeys("%H") for example, , to revert to the home tab, but it does not always work, only sometimes. Cindi Meister Microsoft MVP told me of the sendkeys trick.

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=3663291&SiteID=1

Good luck, please let me know if you find a better way!

Ken Puls
08-12-2008, 10:09 PM
Hi there,

As Microsoft gave us no way to programatically activate tabs, sendkeys is our only option (unfortunately). Give this a try:

Sub ActivateHomeTab()
WordBasic.SendKeys "%H%"
End Sub
It's going to send ALT + H + ALT to the active window. So if you want it to work, the main app needs focus.

I.e. if your user clicks somewhere mid stride and takes focus, it may not complete. If a userform has focus, it may not work, if... you get the idea.

We actually cover this topic, (although using Application.Sendkeys for Excel,) as well as enabling and repurposing controls in RibbonX - Customizing the Office 2007 Ribbon (http://www.amazon.com/RibbonX-Customizing-Office-2007-Ribbon/dp/0470191112/ref=sr_1_1?ie=UTF8&s=books&qid=1218207991&sr=8-1) starting on page 404.

HTH,

evamads
08-15-2008, 02:55 PM
Thanks a lot - that was just what I was looking for :bow:

TonyJollans
09-08-2008, 03:09 PM
There is, at least, one way to do this - using Accessibility.

I have just written up a brief web page on it, with a demonstation Word template available for download:

http://www.wordarticles.com/Shorts/RibbonVBA/RibbonVBADemo.htm

Ken Puls
09-08-2008, 08:32 PM
Thanks Tony. I'll have to dig into that when I've got a bit of time. :)

Djblois
11-05-2008, 09:47 AM
How do I get this to work with Excel instead?