Consulting

Results 1 to 7 of 7

Thread: Solved: VBA code to select a specific tab

  1. #1
    VBAX Regular
    Joined
    Jul 2008
    Posts
    29
    Location

    Solved: VBA code to select a specific tab

    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

  2. #2
    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/Sho...63291&SiteID=1

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

  3. #3
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    Hi there,

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

    [vba]Sub ActivateHomeTab()
    WordBasic.SendKeys "%H%"
    End Sub[/vba]
    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 starting on page 404.

    HTH,
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  4. #4
    VBAX Regular
    Joined
    Jul 2008
    Posts
    29
    Location
    Thanks a lot - that was just what I was looking for

  5. #5
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    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/R...bonVBADemo.htm
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  6. #6
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    Thanks Tony. I'll have to dig into that when I've got a bit of time.
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  7. #7
    VBAX Master
    Joined
    Jun 2006
    Posts
    1,091
    Location
    How do I get this to work with Excel instead?
    Thank You,
    Daniel Blois
    http://studenthacker.blogspot.com/

Posting Permissions

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