Is it possible to change the default tab everytime I run MS Word 2

Z

- zmarlonz -

Is it possible to change the default tab everytime I run MS Word 2007?

For example, when I open Word 2007, the default tab is HOME, then I decided
to click the ADDINS to show my custom toolbars. Then close the application.
The next time the application is run, I wanted to see that the default tab is
the ADDINS.

One more thing, is this also possible programmatically? I am embedding
MSWord library in my program which is responsible for launching MS Word.

Please help.

Thank you in advance.
 
C

Cindy M.

Hi -,
Is it possible to change the default tab everytime I run MS Word 2007?

By design, no. The philosophy behind the Ribbon is that the user should always
see the same thing, so that he always knows where to find things. Note that I'm
not saying I agree with this, just that this is how the MS team was thinking...

In reality, there are some things you can do. In no particular order:

1. Run a SendKeys to emulate the user pressing Alt+[keytip assigned to the Tab]

2. Use the Accessibility interface provided by the Ribbon UI to select a Tab.
See:
http://wordarticles.com/Shorts/RibbonVBA/RibbonVBADemo.htm
http://blogs.msdn.com/pranavwagh/archive/2008/01/21/how-to-switch-ribbon-
tab-programmatically-looks-simple.aspx
http://msdn.microsoft.com/en-us/library/bb404170.aspx

3. Rather than using static XML to define the Ribbon, create the RibbonXML on-
the-fly and load that in the GetCustomUI method. Some discussions:
http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/86c1fc3c-2707-
47b8-ab3c-c20028eacf4c/
http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/d7e8e221-a8b2-
4d94-becb-eebb1a7ec751/


Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 
Z

- zmarlonz -

Hi Cindy,

You reply was very helpful and I was able to find the solution based on the
options you provided. Thank you so much. :)

I opted to #1 using the SendKeys, though not really using the same API but
similar keyboard events, keybd_event. Another option is to use SendInput.

Please refer below for the snippet:

//$2 Used only for Word 2007.
if (IsMSWord2007())
{
//$2 Get the window hanlde of the Word application.
HWND hWndWord = GetMasterWordHWnd();

//$2 Make it the active window.
SetForegroundWindow(hWndWord);
SetFocus(hWndWord);

//$2 Press Alt to show the shortcut keys.
keybd_event(VK_MENU, 0, 0, 0);
keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);

//$2 Press 'X' for Add-ins.
//$2 This will select Add-ins tab.
keybd_event((BYTE)VkKeyScan('X'), 0, 0, 0);
keybd_event((BYTE)VkKeyScan('X'), 0, KEYEVENTF_KEYUP, 0);

//$2 Press Alt again to remove the shortcut keys.
keybd_event(VK_MENU, 0, 0, 0);
keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
}

If you noticed, the key is pressed down and up before any other key is
pressed. This is because the handling for 'Add-ins' tab was different
compared to other tab like, 'Home', 'Mailings', etc...

For these mentioned tabs, here is the sequence in order to make it active
immediately:
Alt DOWN - activate tab shortcut keys
'H' DOWN for 'Home' ('M' for 'Mailings') - immediately activates Home tab
'H' UP
Alt UP
Alt DOWN and UP - to deactivate shortcut keys

Meanwhile for 'Add-ins'
Alt DOWN - activate tab shortcut keys
Alt UP
'X' DOWN for 'Add-ins' - to activate 'Add-ins' tab
'X' UP
Alt DOWN and UP - to deactivate shortcut keys

Hope this helps. :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top