Control of dialog boxes

P

Praful

Hello All,
Is it possible that we get the control of any dialog box that is opened when
we click any menu item. e.g. File->Page Setup opens a dialog box,
format->Autocorrect options open a dialog box,etc. I am coding in vb.net and
want to get handle of these windows.

Please help.

GS
 
C

Chuck Henrich

The Dialogs collection object allows you to manipulate Word's built in
dialogs. Information in VBE help should get you started.

HTH
 
P

Praful

Hi,

Can you provide me some links from where i can start my studies.

Thanks in advance for the same.

GS
 
C

Chuck Henrich

If you open Word, drill down through the Tools menu to Macro > Visual Basic
Editor and then use Help in the Visual Basic Editor (VBE) you'll find the
information you need.
 
P

Praful

Hi Chuck,

I am still not able to track any information. I will once again explain you
in detail what i want. When I click File-> Page Setup menu item a Page setup
dialog box opens. Now when we click OK, then I want to get which orientation
was selected by the user and then depending on the same i have to do some
changes. so i am not able to get the orientation details after the OK button
is clicked. I think I have clarified my issue to you.

GS
 
C

Chuck Henrich

You really need to take the time to read through the VBE help on Dialogs as
well as related links (especially "Displaying built-in Word dialog boxes" and
"Built-in dialog box argument lists"). All the information you need is
there. I'm assuming that as a developer you have Word installed and that
you installed the VBA help files.

In a nutshell, you "display" the dialog (if you want to collect information
but not execute the dialog settings) or "show" the dialog (if you want to
collect information and then execute the settings) and then use a built in
argument to return a value from the dialog.

For instance, adapting an example from the VBE help topic "Displaying
built-in Word dialog boxes":

With Dialogs(wdDialogFilePageSetup)
.Display
MsgBox .Orientation
End With

will display the Page Setup dialog; when the user clicks OK a message box
shows the numeric constant value of the .Orientation setting but because the
dialog was "displayed" the change isn't made to the .Orientation setting.
For information on how to get numeric constant values see the MS
KnowledgeBase article 239930 "How To Obtain Built-In Constant Values for an
Office Application"
(http://support.microsoft.com/default.aspx?scid=kb;en-us;239930).

HTH
 
P

Praful

Hi,

Thanks a lot for the help.

I have one more question and want your help. Is it possible that we somehow
restrict word to add entries in Undo stack or is it possible that we make a
set of events act as one Undo event.

GS
 
C

Chuck Henrich

You're welcome for the help.

As for the undo question, I don't believe you can pick and choose which
event to undo from the stack. You should start another thread for this
question because someone else may have an idea.
 
P

Praful

Me back again.......
Just a small issue left. I am calling a PageSetup dialog box on Page Setup
click only and then i am even able to take the return type (thanks for the
path you shown me). But i am getting one issue that Word is also opening the
PageSetup window once I close mine. Is it possible that the Window that Word
launches is not shown and the total function is overriden by my function.

GS
 
P

Praful

Dim dlgPgSetup As Microsoft.Office.Interop.Word.Dialog
Dim retval As Long
dlgPgSetup = AppObj.Dialogs(WdWordDialog.wdDialogFilePageSetup)
retval = dlgPgSetup.Show
If retval = -1 Then
If CheckCLI() = False Then 'CheckCLI is my function
Exit Sub
Else
ClassificationBox(0) ' ClassificationBox is my
function
End If
End If
 
C

Chuck Henrich

The problem may be that your code is showing the dialog after the user has
already clicked PageSetup. If you're trapping the PageSetup click event then
you don't need to show the dialog again.

You could set the CancelDefault argument of the PageSetup Click event to
True to prevent the built in command from executing. Then your code can show
the dialog and deal with the return value etc.
 
P

Praful

I have tried the CancelDefault = true but the same problem persists. This is
the issue. Is it possible that I get a return type from the dialog box that
is opened by Word itself. Then the problem for me will be solved as i will
not be opening a new dialog box and thus trapping the word's dialog will
solve my problem.

GS
 
C

Chuck Henrich

As far as I'm aware, you can only return values from dialog boxes that are
objects in your code - otherwise, how would your code know what they are?
You'll have to explore why CancelDefault isn't working for you and I don't
have any ideas on that score. Sorry.
 

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