Programmatically manipulate the Office Ribbon

G

GribFritz

Hey all,

My issue is with a VB program that automatically generates Excel files. If
the user has an instance of Excel open, attempting to close a workbook with a
print preview dialog causes the app to hang. Likewise, I have a call to
GetObject that causes the app to hang when print preview is open:

To prevent these calls from hanging, any instances of Excel with a print
preview window open, need to be closed. Programmatically, I accomplish this
with some API work and automatic button clicking. However, in Excel 2007 ,
this fails due to the ribbon.

The Ribbon appears to be a netuihwnd window. It has no hwnd. The buttons on
the window do not belong to the "button" class (or ANY class as far as I can
tell) so I can't programmatically press them.

Hopefully, some of you gurus can help me as hwnd-less windows with buttons
that aren't really buttons is a bit beyond me. If there is a better way to
close a workbook that is in print preview mode that doesn't cause an app to
hang, I'm all ears. Barring that, any programmatic way to close an Excel 2007
print preview window would be great. Thanks in advance.

Fritz
 
J

Jim Cone

Fritz,
If you are still there?...
If you have a reference to the Excel application (say xlApp) then this should work...

xlApp.ActiveWindow.View = 1 'xlNormalView
--
Jim Cone
Portland, Oregon USA
http://tinyurl.com/ExtrasXL

..
..
..


"GribFritz"
<[email protected]>
wrote in message
Hey all,

My issue is with a VB program that automatically generates Excel files. If
the user has an instance of Excel open, attempting to close a workbook with a
print preview dialog causes the app to hang. Likewise, I have a call to
GetObject that causes the app to hang when print preview is open:

To prevent these calls from hanging, any instances of Excel with a print
preview window open, need to be closed. Programmatically, I accomplish this
with some API work and automatic button clicking. However, in Excel 2007 ,
this fails due to the ribbon.

The Ribbon appears to be a netuihwnd window. It has no hwnd. The buttons on
the window do not belong to the "button" class (or ANY class as far as I can
tell) so I can't programmatically press them.

Hopefully, some of you gurus can help me as hwnd-less windows with buttons
that aren't really buttons is a bit beyond me. If there is a better way to
close a workbook that is in print preview mode that doesn't cause an app to
hang, I'm all ears. Barring that, any programmatic way to close an Excel 2007
print preview window would be great. Thanks in advance.

Fritz
 

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