PDA

View Full Version : Dynamic toolbar fails under certain condition



ragingradish
07-06-2007, 08:44 AM
I've built a custom toolbar to add certain bits of functionality to both Word and Excel - they are built dynamically as the application loads and go something like this:


Private Sub Workbook_Open()

'toolbar building code here

End Sub

The code is stored in an xls file at C:\Documents and Settings\ME\Application Data\Microsoft\Excel\XLSTART and it runs just fine in all scenarios, except one.

As a component of this toolbar, I've included buttons which create a new document from a template in either Word or Excel.

When launching a new document (using said button) from within Excel, the toolbar remains. When using the button from Word (to launch a new Excel doc), the toolbar doesn't load.

The code that does this from Word is:


Sub newXLS()

Set fSys = CreateObject("Scripting.FileSystemObject")

templateTarget = "C:\documents and settings\all users\templates\wp_template.xlt"

If fSys.FileExists(templateTarget) Then

Set xls = CreateObject("Excel.Application")

Set newXl = xls.Workbooks.Add(Template:=templateTarget)

xls.Visible = True

Else

MsgBox "Template not installed.", 48

End If

End Sub


The code that does this from Excel is exactly the same, except it doesn't create the Excel object.

I'm guessing this has something to creating the object outside of Excel but I'm at a loss as to how to correct this. Does anyone know if this can be corrected?

Bob Phillips
07-06-2007, 10:14 AM
Odd. It works fine for me, but I swear the first time I tried it it did not. I switched the Visible command prior to the open, and thougt that was why, but I then switched it back and it still worked fine.