View Full Version : Solved: Odd file open behaviour with RibbonX

03-29-2009, 06:44 PM
I'm in the process of migrating a slew of Office 2003 code to Office 2007, and will have to move a lot of commandbar functionality to custom tabs, groups, etc. My only tools will be VBA and the Custom UI Editor/XML Notepad pair.

Anyway, my immediate problem is that when my callback runs code to add a new document to the Documents collection with a specific template, Word reports the file is corrupt and throws error 5151 (corrupt file). If I open the file 'manually' with File->Open, the contents and macros in it appear to be healthy. Does this sound familiar to anyone? I've tried the Open and Repair method in Word, but it has no apparent effect; the error continues. Any clues on this would, of course, be greatly appreciated.

The XML is embedded in a global template loaded at startup. The callback is in a module named 'modRibbon' and it calls a Sub in another module in the same project named 'modMain. The Sub itself contains a single line, and this is where the error is thrown:

Documents.Add Options.DefaultFilePath(wdUserTemplatesPath) & Application.PathSeparator & "Referral Packager.dotm"

Backing up a bit, here is the RibbonX for my button:

<button id="btnReferral" label="Package Referrals" imageMso="MailMergeMergeToDocument"
onAction="modRibbon.button_onAction" />

. . . and the button_onAction callback itself:

Sub button_onAction(ByVal control As IRibbonControl)

Select Case control.ID
. . .
Case Is = "btnReferral"
. . .
Case Else
'Do nothing
End Select
End Sub 'button_onAction

Thanks for your time,

Bob Phillips
04-03-2009, 01:41 PM
This now says solved. Can you share the solution with us?

04-04-2009, 11:13 AM
The "solution" is to not rename templates so that your code is looking for a file that no longer exists.:blush