Display New Document task pane

R

Rich007

Hi.
This should be simple. How do I show the new document task pane using vba
(Word 2003)?

The background:
I want to intercept the File > New... button so that I can perform a class
initialization, so my Application Events work after Word is launched from
Internet Explorer, i.e.
Set oAppClass.oApp = Word.Application
Once that line of code is run, the oApp_NewDocument event macro will run
when a new document is opened.

If I use the usual inctercept method to create a new macro from the Word
Commands, (http://word.mvps.org/FAQs/MacrosVBA/InterceptSavePrint.htm)
I get...

Sub FileNew()
' FileNew Macro
' Opens New Document taskpane [NO IT DOESN'T!]
'
Dialogs(wdDialogFileNew).Show
End Sub

....these only show the "New" dialog window (with the tabs where you can
select templates). I want to be able to run an intercept of the New...
button and NOT change the functionality of Word- i.e. I still want to be able
to show the New Documents task pane.

Any ideas?
Rich
 
S

Stefan Blom

There doesn't seem to be a way to display the New Document task pane via
VBA. If you look in the Object Browser (of the Visual Basic Editor), you'll
see that there is no wdTaskPanes constant defined that corresponds to New
Document.
 
R

Rich007

Many thanks Stefan for confirming my fears.

I’m happy to say I’ve found a work around to intercept the “New..." button
and still be able to show the New Document task pane. Still, shame on
Microsoft that this isn’t possible without all of this faff! Here’s how the
work around works:

1) In an add-in (.dot file to be saved in the Word/STARTUP directory),
create a new toolbar called Hidden. Add the built in “New…†button to it.

2) On the File menu and Standard toolbar, also have the “New...†button in
place.

3) Save the following code in your add-in. This will run whenever either
the button on the File menu or the Standard toolbar are pressed. Add the
code you want to run when intercepting the “New…†button where indicated.

Sub FileNewX()
' Opens New Document task pane
'
‘YOUR OTHER CODE HERE

Application.ScreenUpdating = False
CommandBars("Hidden").Enabled = True

CommandBars("Hidden").Controls("New...").Execute
‘This “clicks†the built-in “New…†button on the Hidden toolbar
‘to display the New Document task pane.

CommandBars("Hidden").Enabled = False
Application.ScreenUpdating = True
End Sub

4) Run the following code with the add-in open and active:
Sub Construction()
CustomizationContext = ActiveDocument
CommandBars("Standard").Controls("New...") _
.OnAction = "FileNewX"
CommandBars("Menu Bar").Controls("File") _
.Controls("New...").OnAction = "FileNewX"
End Sub

Now the FileNewX macro will fire when the user clicks on either of the two,
now dummy, “New…†buttons in the File menu or on the Standard toolbar, your
code will run and then the New Document task pane will be shown (works in
Word 2003).

Enjoy.
Cheers
Rich


Stefan Blom said:
There doesn't seem to be a way to display the New Document task pane via
VBA. If you look in the Object Browser (of the Visual Basic Editor), you'll
see that there is no wdTaskPanes constant defined that corresponds to New
Document.

--
Stefan Blom
Microsoft Word MVP



Rich007 said:
Hi.
This should be simple. How do I show the new document task pane using vba
(Word 2003)?

The background:
I want to intercept the File > New... button so that I can perform a class
initialization, so my Application Events work after Word is launched from
Internet Explorer, i.e.
Set oAppClass.oApp = Word.Application
Once that line of code is run, the oApp_NewDocument event macro will run
when a new document is opened.

If I use the usual inctercept method to create a new macro from the Word
Commands, (http://word.mvps.org/FAQs/MacrosVBA/InterceptSavePrint.htm)
I get...

Sub FileNew()
' FileNew Macro
' Opens New Document taskpane [NO IT DOESN'T!]
'
Dialogs(wdDialogFileNew).Show
End Sub

...these only show the "New" dialog window (with the tabs where you can
select templates). I want to be able to run an intercept of the New...
button and NOT change the functionality of Word- i.e. I still want to be
able
to show the New Documents task pane.

Any ideas?
Rich
 
S

Stefan Blom

That is a very good idea! When I think about it, I realize that you can
actually make that simpler, by executing the command without adding it to a
toolbar first:

Dim c As CommandBarControl
Set c = CommandBars.FindControl(ID:=18)
c.Execute

--
Stefan Blom
Microsoft Word MVP



Rich007 said:
Many thanks Stefan for confirming my fears.

I'm happy to say I've found a work around to intercept the "New..." button
and still be able to show the New Document task pane. Still, shame on
Microsoft that this isn't possible without all of this faff! Here's how
the
work around works:

1) In an add-in (.dot file to be saved in the Word/STARTUP directory),
create a new toolbar called Hidden. Add the built in "New." button to it.

2) On the File menu and Standard toolbar, also have the "New..." button in
place.

3) Save the following code in your add-in. This will run whenever either
the button on the File menu or the Standard toolbar are pressed. Add the
code you want to run when intercepting the "New." button where indicated.

Sub FileNewX()
' Opens New Document task pane
'
'YOUR OTHER CODE HERE

Application.ScreenUpdating = False
CommandBars("Hidden").Enabled = True

CommandBars("Hidden").Controls("New...").Execute
'This "clicks" the built-in "New." button on the Hidden toolbar
'to display the New Document task pane.

CommandBars("Hidden").Enabled = False
Application.ScreenUpdating = True
End Sub

4) Run the following code with the add-in open and active:
Sub Construction()
CustomizationContext = ActiveDocument
CommandBars("Standard").Controls("New...") _
.OnAction = "FileNewX"
CommandBars("Menu Bar").Controls("File") _
.Controls("New...").OnAction = "FileNewX"
End Sub

Now the FileNewX macro will fire when the user clicks on either of the
two,
now dummy, "New." buttons in the File menu or on the Standard toolbar,
your
code will run and then the New Document task pane will be shown (works in
Word 2003).

Enjoy.
Cheers
Rich


Stefan Blom said:
There doesn't seem to be a way to display the New Document task pane via
VBA. If you look in the Object Browser (of the Visual Basic Editor),
you'll
see that there is no wdTaskPanes constant defined that corresponds to New
Document.

--
Stefan Blom
Microsoft Word MVP



Rich007 said:
Hi.
This should be simple. How do I show the new document task pane using
vba
(Word 2003)?

The background:
I want to intercept the File > New... button so that I can perform a
class
initialization, so my Application Events work after Word is launched
from
Internet Explorer, i.e.
Set oAppClass.oApp = Word.Application
Once that line of code is run, the oApp_NewDocument event macro will
run
when a new document is opened.

If I use the usual inctercept method to create a new macro from the
Word
Commands, (http://word.mvps.org/FAQs/MacrosVBA/InterceptSavePrint.htm)
I get...

Sub FileNew()
' FileNew Macro
' Opens New Document taskpane [NO IT DOESN'T!]
'
Dialogs(wdDialogFileNew).Show
End Sub

...these only show the "New" dialog window (with the tabs where you can
select templates). I want to be able to run an intercept of the New...
button and NOT change the functionality of Word- i.e. I still want to
be
able
to show the New Documents task pane.

Any ideas?
Rich
 
R

Rich007

Ah, thanks Stefan, I like it. One question: will that always work, even if
the command ID in question isn't present on any commandbars (whether enabled,
visible or neither)?
Cheers
Rich

Stefan Blom said:
That is a very good idea! When I think about it, I realize that you can
actually make that simpler, by executing the command without adding it to a
toolbar first:

Dim c As CommandBarControl
Set c = CommandBars.FindControl(ID:=18)
c.Execute

--
Stefan Blom
Microsoft Word MVP



Rich007 said:
Many thanks Stefan for confirming my fears.

I'm happy to say I've found a work around to intercept the "New..." button
and still be able to show the New Document task pane. Still, shame on
Microsoft that this isn't possible without all of this faff! Here's how
the
work around works:

1) In an add-in (.dot file to be saved in the Word/STARTUP directory),
create a new toolbar called Hidden. Add the built in "New." button to it.

2) On the File menu and Standard toolbar, also have the "New..." button in
place.

3) Save the following code in your add-in. This will run whenever either
the button on the File menu or the Standard toolbar are pressed. Add the
code you want to run when intercepting the "New." button where indicated.

Sub FileNewX()
' Opens New Document task pane
'
'YOUR OTHER CODE HERE

Application.ScreenUpdating = False
CommandBars("Hidden").Enabled = True

CommandBars("Hidden").Controls("New...").Execute
'This "clicks" the built-in "New." button on the Hidden toolbar
'to display the New Document task pane.

CommandBars("Hidden").Enabled = False
Application.ScreenUpdating = True
End Sub

4) Run the following code with the add-in open and active:
Sub Construction()
CustomizationContext = ActiveDocument
CommandBars("Standard").Controls("New...") _
.OnAction = "FileNewX"
CommandBars("Menu Bar").Controls("File") _
.Controls("New...").OnAction = "FileNewX"
End Sub

Now the FileNewX macro will fire when the user clicks on either of the
two,
now dummy, "New." buttons in the File menu or on the Standard toolbar,
your
code will run and then the New Document task pane will be shown (works in
Word 2003).

Enjoy.
Cheers
Rich


Stefan Blom said:
There doesn't seem to be a way to display the New Document task pane via
VBA. If you look in the Object Browser (of the Visual Basic Editor),
you'll
see that there is no wdTaskPanes constant defined that corresponds to New
Document.

--
Stefan Blom
Microsoft Word MVP



Hi.
This should be simple. How do I show the new document task pane using
vba
(Word 2003)?

The background:
I want to intercept the File > New... button so that I can perform a
class
initialization, so my Application Events work after Word is launched
from
Internet Explorer, i.e.
Set oAppClass.oApp = Word.Application
Once that line of code is run, the oApp_NewDocument event macro will
run
when a new document is opened.

If I use the usual inctercept method to create a new macro from the
Word
Commands, (http://word.mvps.org/FAQs/MacrosVBA/InterceptSavePrint.htm)
I get...

Sub FileNew()
' FileNew Macro
' Opens New Document taskpane [NO IT DOESN'T!]
'
Dialogs(wdDialogFileNew).Show
End Sub

...these only show the "New" dialog window (with the tabs where you can
select templates). I want to be able to run an intercept of the New...
button and NOT change the functionality of Word- i.e. I still want to
be
able
to show the New Documents task pane.

Any ideas?
Rich
 
S

Stefan Blom

Yes, it should work at all times.

--
Stefan Blom
Microsoft Word MVP



Rich007 said:
Ah, thanks Stefan, I like it. One question: will that always work, even
if
the command ID in question isn't present on any commandbars (whether
enabled,
visible or neither)?
Cheers
Rich

Stefan Blom said:
That is a very good idea! When I think about it, I realize that you can
actually make that simpler, by executing the command without adding it to
a
toolbar first:

Dim c As CommandBarControl
Set c = CommandBars.FindControl(ID:=18)
c.Execute

--
Stefan Blom
Microsoft Word MVP



Rich007 said:
Many thanks Stefan for confirming my fears.

I'm happy to say I've found a work around to intercept the "New..."
button
and still be able to show the New Document task pane. Still, shame on
Microsoft that this isn't possible without all of this faff! Here's
how
the
work around works:

1) In an add-in (.dot file to be saved in the Word/STARTUP directory),
create a new toolbar called Hidden. Add the built in "New." button to
it.

2) On the File menu and Standard toolbar, also have the "New..." button
in
place.

3) Save the following code in your add-in. This will run whenever
either
the button on the File menu or the Standard toolbar are pressed. Add
the
code you want to run when intercepting the "New." button where
indicated.

Sub FileNewX()
' Opens New Document task pane
'
'YOUR OTHER CODE HERE

Application.ScreenUpdating = False
CommandBars("Hidden").Enabled = True

CommandBars("Hidden").Controls("New...").Execute
'This "clicks" the built-in "New." button on the Hidden
toolbar
'to display the New Document task pane.

CommandBars("Hidden").Enabled = False
Application.ScreenUpdating = True
End Sub

4) Run the following code with the add-in open and active:
Sub Construction()
CustomizationContext = ActiveDocument
CommandBars("Standard").Controls("New...") _
.OnAction = "FileNewX"
CommandBars("Menu Bar").Controls("File") _
.Controls("New...").OnAction = "FileNewX"
End Sub

Now the FileNewX macro will fire when the user clicks on either of the
two,
now dummy, "New." buttons in the File menu or on the Standard toolbar,
your
code will run and then the New Document task pane will be shown (works
in
Word 2003).

Enjoy.
Cheers
Rich


:

There doesn't seem to be a way to display the New Document task pane
via
VBA. If you look in the Object Browser (of the Visual Basic Editor),
you'll
see that there is no wdTaskPanes constant defined that corresponds to
New
Document.

--
Stefan Blom
Microsoft Word MVP



Hi.
This should be simple. How do I show the new document task pane
using
vba
(Word 2003)?

The background:
I want to intercept the File > New... button so that I can perform a
class
initialization, so my Application Events work after Word is launched
from
Internet Explorer, i.e.
Set oAppClass.oApp = Word.Application
Once that line of code is run, the oApp_NewDocument event macro will
run
when a new document is opened.

If I use the usual inctercept method to create a new macro from the
Word
Commands,
(http://word.mvps.org/FAQs/MacrosVBA/InterceptSavePrint.htm)
I get...

Sub FileNew()
' FileNew Macro
' Opens New Document taskpane [NO IT DOESN'T!]
'
Dialogs(wdDialogFileNew).Show
End Sub

...these only show the "New" dialog window (with the tabs where you
can
select templates). I want to be able to run an intercept of the
New...
button and NOT change the functionality of Word- i.e. I still want
to
be
able
to show the New Documents task pane.

Any ideas?
Rich
 
R

Rich007

Hi Stefan,
Sorry to contradict you, but your proposed method will not quite work, since
the buttons on the File menu and the Standard toolbar still have the button
ID of 18, even though we have assigned their OnAction to our new macro
"FileNewX". So when you do the FindControl(ID:=18) one of those two buttons
is found and is then executed... which then calls the FileNewX macro again!

To make your way work, you would have to put the actual macro button for
FileNewX on to the File and Standard commandbars, removing any original
"New..." button. You would then have to rename the button "New...", copy the
button image and also update the ToolTipText... I think it's easier to assign
the macro to the existing button rather than recreate the button from
scratch, but in theory either way can be made to work.

I do acknowledge that the .Execute command works whether the commandbar is
Enabled or not, so I did end up removing a couple of lines of code :eek:)

Thank you very much for your help and for the valuable work you and your
fellow contributors do on this site (usually fixing the messes left behind by
Microsoft!).

For future clarity, here again is the method I used to intercept the New...
button and still have the New Document task pane show:

1) In an add-in (.dot file to be saved in the Word/STARTUP directory),
create a new toolbar called Hidden. Add the built in "New..." button to it.

2) On the File menu and Standard toolbar, also have the "New..." button in
place.

3) Save the following code in your add-in. This will run whenever either
the button on the File menu or the Standard toolbar are pressed. Add the
code you want to run when intercepting the "New..." button where indicated
(e.g. initialize Application Events so that when a new document is created
your NewDocument event will fire, even if Word was launched from Internet
Explorer or Outlook).

Sub FileNewX()
' Runs when the user clicks the "New..." button on the
' File menu or on the Standard toolbar. Opens New Document task pane
'
'YOUR OTHER CODE HERE

CommandBars("Hidden").Controls("New...").Execute
'This "clicks" the built-in "New..." button on the Hidden
'toolbar to display the New Document task pane.
End Sub

4) Run the following code with the add-in open and active:
Sub Construction()
CustomizationContext = ActiveDocument
CommandBars("Standard").Controls("New...") _
.OnAction = "FileNewX"
CommandBars("Menu Bar").Controls("File") _
.Controls("New...").OnAction = "FileNewX"
CommandBars("Hidden").Enabled = False
End Sub

Now the FileNewX macro will fire when the user clicks on either of the
two, now dummy, "New..." buttons in the File menu or on the Standard toolbar,
your code will run and then the New Document task pane will be shown (works
in Word 2003).

Enjoy.
Cheers
Rich


Stefan Blom said:
Yes, it should work at all times.

--
Stefan Blom
Microsoft Word MVP


Rich007 said:
Ah, thanks Stefan, I like it. One question: will that always work, even
if the command ID in question isn't present on any commandbars (whether
enabled, visible or neither)?
Cheers
Rich

Stefan Blom said:
That is a very good idea! When I think about it, I realize that you can
actually make that simpler, by executing the command without adding it to
a toolbar first:

Dim c As CommandBarControl
Set c = CommandBars.FindControl(ID:=18)
c.Execute

--
Stefan Blom
Microsoft Word MVP



Many thanks Stefan for confirming my fears.

I'm happy to say I've found a work around to intercept the "New..."
button and still be able to show the New Document task pane. Still, shame
on Microsoft that this isn't possible without all of this faff! Here's
how the work around works:

1) In an add-in (.dot file to be saved in the Word/STARTUP directory),
create a new toolbar called Hidden. Add the built in "New." button to
it.

2) On the File menu and Standard toolbar, also have the "New..." button
in place.

3) Save the following code in your add-in. This will run whenever
either the button on the File menu or the Standard toolbar are pressed.
Add the code you want to run when intercepting the "New." button where
indicated.

Sub FileNewX()
' Opens New Document task pane
'
'YOUR OTHER CODE HERE

Application.ScreenUpdating = False
CommandBars("Hidden").Enabled = True

CommandBars("Hidden").Controls("New...").Execute
'This "clicks" the built-in "New." button on the Hidden
'toolbar to display the New Document task pane.

CommandBars("Hidden").Enabled = False
Application.ScreenUpdating = True
End Sub

4) Run the following code with the add-in open and active:
Sub Construction()
CustomizationContext = ActiveDocument
CommandBars("Standard").Controls("New...") _
.OnAction = "FileNewX"
CommandBars("Menu Bar").Controls("File") _
.Controls("New...").OnAction = "FileNewX"
End Sub

Now the FileNewX macro will fire when the user clicks on either of the
two, now dummy, "New." buttons in the File menu or on the Standard
toolbar, your code will run and then the New Document task pane will be
shown (works in Word 2003).

Enjoy.
Cheers
Rich


:

There doesn't seem to be a way to display the New Document task pane
via VBA. If you look in the Object Browser (of the Visual Basic Editor),
you'll see that there is no wdTaskPanes constant defined that corresponds
to New Document.

--
Stefan Blom
Microsoft Word MVP



Hi.
This should be simple. How do I show the new document task pane
using vba (Word 2003)?

The background:
I want to intercept the File > New... button so that I can perform a
class initialization, so my Application Events work after Word is launched
from Internet Explorer, i.e.
Set oAppClass.oApp = Word.Application
Once that line of code is run, the oApp_NewDocument event macro will
run when a new document is opened.

If I use the usual inctercept method to create a new macro from the
Word Commands,
(http://word.mvps.org/FAQs/MacrosVBA/InterceptSavePrint.htm)
I get...

Sub FileNew()
' FileNew Macro
' Opens New Document taskpane [NO IT DOESN'T!]
'
Dialogs(wdDialogFileNew).Show
End Sub

...these only show the "New" dialog window (with the tabs where you
can select templates). I want to be able to run an intercept of the
New... button and NOT change the functionality of Word- i.e. I still want
to be able to show the New Documents task pane.

Any ideas?
Rich
 
S

Stefan Blom

Well, of course, since you have assigned a custom macro to the command whose
ID is 18, that custom macro will run when you execute that command. Sorry
about any confusion!

I was thinking of a scenario where you don't assign a macro, but instead
intercept the appropriate command with the code I suggested.

--
Stefan Blom
Microsoft Word MVP



Rich007 said:
Hi Stefan,
Sorry to contradict you, but your proposed method will not quite work,
since
the buttons on the File menu and the Standard toolbar still have the
button
ID of 18, even though we have assigned their OnAction to our new macro
"FileNewX". So when you do the FindControl(ID:=18) one of those two
buttons
is found and is then executed... which then calls the FileNewX macro
again!

To make your way work, you would have to put the actual macro button for
FileNewX on to the File and Standard commandbars, removing any original
"New..." button. You would then have to rename the button "New...", copy
the
button image and also update the ToolTipText... I think it's easier to
assign
the macro to the existing button rather than recreate the button from
scratch, but in theory either way can be made to work.

I do acknowledge that the .Execute command works whether the commandbar is
Enabled or not, so I did end up removing a couple of lines of code :eek:)

Thank you very much for your help and for the valuable work you and your
fellow contributors do on this site (usually fixing the messes left behind
by
Microsoft!).

For future clarity, here again is the method I used to intercept the
New...
button and still have the New Document task pane show:

1) In an add-in (.dot file to be saved in the Word/STARTUP directory),
create a new toolbar called Hidden. Add the built in "New..." button to
it.

2) On the File menu and Standard toolbar, also have the "New..." button in
place.

3) Save the following code in your add-in. This will run whenever either
the button on the File menu or the Standard toolbar are pressed. Add the
code you want to run when intercepting the "New..." button where indicated
(e.g. initialize Application Events so that when a new document is created
your NewDocument event will fire, even if Word was launched from Internet
Explorer or Outlook).

Sub FileNewX()
' Runs when the user clicks the "New..." button on the
' File menu or on the Standard toolbar. Opens New Document task pane
'
'YOUR OTHER CODE HERE

CommandBars("Hidden").Controls("New...").Execute
'This "clicks" the built-in "New..." button on the Hidden
'toolbar to display the New Document task pane.
End Sub

4) Run the following code with the add-in open and active:
Sub Construction()
CustomizationContext = ActiveDocument
CommandBars("Standard").Controls("New...") _
.OnAction = "FileNewX"
CommandBars("Menu Bar").Controls("File") _
.Controls("New...").OnAction = "FileNewX"
CommandBars("Hidden").Enabled = False
End Sub

Now the FileNewX macro will fire when the user clicks on either of the
two, now dummy, "New..." buttons in the File menu or on the Standard
toolbar,
your code will run and then the New Document task pane will be shown
(works
in Word 2003).

Enjoy.
Cheers
Rich


Stefan Blom said:
Yes, it should work at all times.

--
Stefan Blom
Microsoft Word MVP


Rich007 said:
Ah, thanks Stefan, I like it. One question: will that always work,
even
if the command ID in question isn't present on any commandbars (whether
enabled, visible or neither)?
Cheers
Rich

:

That is a very good idea! When I think about it, I realize that you
can
actually make that simpler, by executing the command without adding it
to
a toolbar first:

Dim c As CommandBarControl
Set c = CommandBars.FindControl(ID:=18)
c.Execute

--
Stefan Blom
Microsoft Word MVP



Many thanks Stefan for confirming my fears.

I'm happy to say I've found a work around to intercept the "New..."
button and still be able to show the New Document task pane. Still,
shame
on Microsoft that this isn't possible without all of this faff!
Here's
how the work around works:

1) In an add-in (.dot file to be saved in the Word/STARTUP
directory),
create a new toolbar called Hidden. Add the built in "New." button
to
it.

2) On the File menu and Standard toolbar, also have the "New..."
button
in place.

3) Save the following code in your add-in. This will run whenever
either the button on the File menu or the Standard toolbar are
pressed.
Add the code you want to run when intercepting the "New." button
where
indicated.

Sub FileNewX()
' Opens New Document task pane
'
'YOUR OTHER CODE HERE

Application.ScreenUpdating = False
CommandBars("Hidden").Enabled = True

CommandBars("Hidden").Controls("New...").Execute
'This "clicks" the built-in "New." button on the Hidden
'toolbar to display the New Document task pane.

CommandBars("Hidden").Enabled = False
Application.ScreenUpdating = True
End Sub

4) Run the following code with the add-in open and active:
Sub Construction()
CustomizationContext = ActiveDocument
CommandBars("Standard").Controls("New...") _
.OnAction = "FileNewX"
CommandBars("Menu Bar").Controls("File") _
.Controls("New...").OnAction = "FileNewX"
End Sub

Now the FileNewX macro will fire when the user clicks on either of
the
two, now dummy, "New." buttons in the File menu or on the Standard
toolbar, your code will run and then the New Document task pane will
be
shown (works in Word 2003).

Enjoy.
Cheers
Rich


:

There doesn't seem to be a way to display the New Document task
pane
via VBA. If you look in the Object Browser (of the Visual Basic
Editor),
you'll see that there is no wdTaskPanes constant defined that
corresponds
to New Document.

--
Stefan Blom
Microsoft Word MVP



Hi.
This should be simple. How do I show the new document task pane
using vba (Word 2003)?

The background:
I want to intercept the File > New... button so that I can
perform a
class initialization, so my Application Events work after Word is
launched
from Internet Explorer, i.e.
Set oAppClass.oApp = Word.Application
Once that line of code is run, the oApp_NewDocument event macro
will
run when a new document is opened.

If I use the usual inctercept method to create a new macro from
the
Word Commands,
(http://word.mvps.org/FAQs/MacrosVBA/InterceptSavePrint.htm)
I get...

Sub FileNew()
' FileNew Macro
' Opens New Document taskpane [NO IT DOESN'T!]
'
Dialogs(wdDialogFileNew).Show
End Sub

...these only show the "New" dialog window (with the tabs where
you
can select templates). I want to be able to run an intercept of
the
New... button and NOT change the functionality of Word- i.e. I
still want
to be able to show the New Documents task pane.

Any ideas?
Rich
 
S

Stefan Blom

Well, since you have assigned a macro to the command whose ID is 18, it
doesn't work as I said it would. Sorry about any confusion!

I was thinking that it would be easier to intercept the appropriate commands
with the code I suggested.

--
Stefan Blom
Microsoft Word MVP



Rich007 said:
Hi Stefan,
Sorry to contradict you, but your proposed method will not quite work,
since
the buttons on the File menu and the Standard toolbar still have the
button
ID of 18, even though we have assigned their OnAction to our new macro
"FileNewX". So when you do the FindControl(ID:=18) one of those two
buttons
is found and is then executed... which then calls the FileNewX macro
again!

To make your way work, you would have to put the actual macro button for
FileNewX on to the File and Standard commandbars, removing any original
"New..." button. You would then have to rename the button "New...", copy
the
button image and also update the ToolTipText... I think it's easier to
assign
the macro to the existing button rather than recreate the button from
scratch, but in theory either way can be made to work.

I do acknowledge that the .Execute command works whether the commandbar is
Enabled or not, so I did end up removing a couple of lines of code :eek:)

Thank you very much for your help and for the valuable work you and your
fellow contributors do on this site (usually fixing the messes left behind
by
Microsoft!).

For future clarity, here again is the method I used to intercept the
New...
button and still have the New Document task pane show:

1) In an add-in (.dot file to be saved in the Word/STARTUP directory),
create a new toolbar called Hidden. Add the built in "New..." button to
it.

2) On the File menu and Standard toolbar, also have the "New..." button in
place.

3) Save the following code in your add-in. This will run whenever either
the button on the File menu or the Standard toolbar are pressed. Add the
code you want to run when intercepting the "New..." button where indicated
(e.g. initialize Application Events so that when a new document is created
your NewDocument event will fire, even if Word was launched from Internet
Explorer or Outlook).

Sub FileNewX()
' Runs when the user clicks the "New..." button on the
' File menu or on the Standard toolbar. Opens New Document task pane
'
'YOUR OTHER CODE HERE

CommandBars("Hidden").Controls("New...").Execute
'This "clicks" the built-in "New..." button on the Hidden
'toolbar to display the New Document task pane.
End Sub

4) Run the following code with the add-in open and active:
Sub Construction()
CustomizationContext = ActiveDocument
CommandBars("Standard").Controls("New...") _
.OnAction = "FileNewX"
CommandBars("Menu Bar").Controls("File") _
.Controls("New...").OnAction = "FileNewX"
CommandBars("Hidden").Enabled = False
End Sub

Now the FileNewX macro will fire when the user clicks on either of the
two, now dummy, "New..." buttons in the File menu or on the Standard
toolbar,
your code will run and then the New Document task pane will be shown
(works
in Word 2003).

Enjoy.
Cheers
Rich


Stefan Blom said:
Yes, it should work at all times.

--
Stefan Blom
Microsoft Word MVP


Rich007 said:
Ah, thanks Stefan, I like it. One question: will that always work,
even
if the command ID in question isn't present on any commandbars (whether
enabled, visible or neither)?
Cheers
Rich

:

That is a very good idea! When I think about it, I realize that you
can
actually make that simpler, by executing the command without adding it
to
a toolbar first:

Dim c As CommandBarControl
Set c = CommandBars.FindControl(ID:=18)
c.Execute

--
Stefan Blom
Microsoft Word MVP



Many thanks Stefan for confirming my fears.

I'm happy to say I've found a work around to intercept the "New..."
button and still be able to show the New Document task pane. Still,
shame
on Microsoft that this isn't possible without all of this faff!
Here's
how the work around works:

1) In an add-in (.dot file to be saved in the Word/STARTUP
directory),
create a new toolbar called Hidden. Add the built in "New." button
to
it.

2) On the File menu and Standard toolbar, also have the "New..."
button
in place.

3) Save the following code in your add-in. This will run whenever
either the button on the File menu or the Standard toolbar are
pressed.
Add the code you want to run when intercepting the "New." button
where
indicated.

Sub FileNewX()
' Opens New Document task pane
'
'YOUR OTHER CODE HERE

Application.ScreenUpdating = False
CommandBars("Hidden").Enabled = True

CommandBars("Hidden").Controls("New...").Execute
'This "clicks" the built-in "New." button on the Hidden
'toolbar to display the New Document task pane.

CommandBars("Hidden").Enabled = False
Application.ScreenUpdating = True
End Sub

4) Run the following code with the add-in open and active:
Sub Construction()
CustomizationContext = ActiveDocument
CommandBars("Standard").Controls("New...") _
.OnAction = "FileNewX"
CommandBars("Menu Bar").Controls("File") _
.Controls("New...").OnAction = "FileNewX"
End Sub

Now the FileNewX macro will fire when the user clicks on either of
the
two, now dummy, "New." buttons in the File menu or on the Standard
toolbar, your code will run and then the New Document task pane will
be
shown (works in Word 2003).

Enjoy.
Cheers
Rich


:

There doesn't seem to be a way to display the New Document task
pane
via VBA. If you look in the Object Browser (of the Visual Basic
Editor),
you'll see that there is no wdTaskPanes constant defined that
corresponds
to New Document.

--
Stefan Blom
Microsoft Word MVP



Hi.
This should be simple. How do I show the new document task pane
using vba (Word 2003)?

The background:
I want to intercept the File > New... button so that I can
perform a
class initialization, so my Application Events work after Word is
launched
from Internet Explorer, i.e.
Set oAppClass.oApp = Word.Application
Once that line of code is run, the oApp_NewDocument event macro
will
run when a new document is opened.

If I use the usual inctercept method to create a new macro from
the
Word Commands,
(http://word.mvps.org/FAQs/MacrosVBA/InterceptSavePrint.htm)
I get...

Sub FileNew()
' FileNew Macro
' Opens New Document taskpane [NO IT DOESN'T!]
'
Dialogs(wdDialogFileNew).Show
End Sub

...these only show the "New" dialog window (with the tabs where
you
can select templates). I want to be able to run an intercept of
the
New... button and NOT change the functionality of Word- i.e. I
still want
to be able to show the New Documents task pane.

Any ideas?
Rich
 

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