Built in Word dialog problem

H

Haydn Robinson

I'm trying to use on of Word's built in dialogs, namely the table auto-format
dialog. Reading up on MSDN, this should work:

Word.Dialog dlg =
Application.Dialogs[Word.WdWordDialog.wdDialogTableAutoFormat];

However, doing this I get the following error:

"Microsoft Word: This method or property is not available because some or
all of the current selection is not in a table."

What am I doing wrong?
 
J

Jay Freedman

Haydn said:
Oh yes, forgot to mention, using WinXP SP2 and Word 2003 SP1.

Haydn Robinson said:
I'm trying to use on of Word's built in dialogs, namely the table
auto-format dialog. Reading up on MSDN, this should work:

Word.Dialog dlg =
Application.Dialogs[Word.WdWordDialog.wdDialogTableAutoFormat];

However, doing this I get the following error:

"Microsoft Word: This method or property is not available because
some or all of the current selection is not in a table."

What am I doing wrong?

When you execute that line of code, is the selection (insertion point)
inside a table in the active document? That condition must be true in order
to display that dialog from code. (In the UI you can use the Table > Table
AutoFormat command to display the dialog when not in a table, but clicking
OK immediately runs the Insert Table dialog. This is a special case in the
UI and isn't available to code.)

You can test this assumption by calling
Selection.Information(wdWithInTable) -- however you have to mangle that to
get the right syntax -- it returns True if the Selection is entirely within
a table.
 
H

Haydn Robinson

No the selection isn't in a table. What I have is a dialog my end that
allows someone to setup a table, with the added option of picking a
pre-defined Word table style. What I wanted was a button on my dialog that
would bring up the Word auto format dialog, so the user can see what style
they're getting. Looks like I'll have to fall back to a dropdown with just
the names of the styles in.

Thanks for that.

Haydn

Jay Freedman said:
Haydn said:
Oh yes, forgot to mention, using WinXP SP2 and Word 2003 SP1.

Haydn Robinson said:
I'm trying to use on of Word's built in dialogs, namely the table
auto-format dialog. Reading up on MSDN, this should work:

Word.Dialog dlg =
Application.Dialogs[Word.WdWordDialog.wdDialogTableAutoFormat];

However, doing this I get the following error:

"Microsoft Word: This method or property is not available because
some or all of the current selection is not in a table."

What am I doing wrong?

When you execute that line of code, is the selection (insertion point)
inside a table in the active document? That condition must be true in order
to display that dialog from code. (In the UI you can use the Table > Table
AutoFormat command to display the dialog when not in a table, but clicking
OK immediately runs the Insert Table dialog. This is a special case in the
UI and isn't available to code.)

You can test this assumption by calling
Selection.Information(wdWithInTable) -- however you have to mangle that to
get the right syntax -- it returns True if the Selection is entirely within
a table.
 

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