#1
|
|||
|
|||
Problem saving in Word 2007 a dotm Addin developed in Word 2010
I hope someone can help me. I've developed an AddIn in Word 2010 which works fine in Word 2010 on my Windows 7 (English edition) machine. I copy it to my Dev folder on my Word 2007 machine (I should add that this latter machine is French Windows XP SP3, French Office 2007). This AddIn is fairly complex (132 modules, including forms, code and class modules) and references Excel, Outlook and Powerpoint (VBE). So when I open it on the Office 2007 machine (by right-clicking it in Windows Explorer then Open), I expect to get referencing errors, which I do. I then dutifully open the VBE, remove the Excel, Outlook and Powerpoint references (14.0) which are naturally reported as missing, and add the 12.0 references from the dropdown list. Interestingly enough, the Word reference has automatically changed to 12.0! All the required references are now check-marked, including scrrun (Microsoft Scripting). I compile and immediately get an error in French (something like "can't find object library or wrong object library"), even though all the References are apparently correct, and I've ascertained their physical presence in the reported paths. More worryingly, I can't save the AddIn, either in the VBE window or in the main Word window. I always get a very unhelpful error "An error has occurred" followed by the path. After some research, I'm wondering whether a "reverse-engineering" registry hack is in order, after finding this on technet: In Office 2010, Visual Basic for Applications (VBA) 6.0 was updated to VBA 7.0. VBA 7.0 settings were reset to their defaults after migration instead of automatically repopulating. This occurred because the registry settings for VBA are in a different hive in Office 2010: Office 2010 HKEY_CURRENT_USER\SOFTWARE\Microsoft\VBA\7.0\Commo n "HKEY_CURRENT_USER\SOFTWARE\Microsoft\VBA\6.0\Comm on" in 2000 thru 2007 "HKEY_CURRENT_USER\SOFTWARE\Microsoft\VBA\7.0\Comm on" in 2010 I don't really understand this, but should I add a '7.0' key in my 2007 machine's registry? Or is the problem elsewhere? |
#2
|
||||
|
||||
Hi Richard,
Aside from making sure you're not using functions that were introduced with Office 2010, you could probably save yourself some grief by: • modifying the code to use late binding; • using Office 2007 as the development platform (the references will automatically adjust for later Office versions); or • exporting the various module from Office 2010, then importing them under Office 2007 (and redoing the references). Note also that you'll need to review your use of separators in the code, because the French version will use ';', for example, where the English version uses ','. Indeed, the "can't find object library or wrong object library" error might be because your addin is looking for a library for use with another language. The reason the Word reference has automatically changed to 12.0 is that it's one you didn't set - it's automatically set to whatever the current version is.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
Late binding must be the way to go
Thanks so much Paul, very helpful.
Importing 132 modules each time I update my AddIn is too complicated. I have checks in my code for argument separator (,/ and other French specifics, and I'm carfeful not to use any features introduced with Word 2010 (I originally developed the AddIn in Word 2003 and hope to make this 2010 version backward compatible, thanks to you). So late binding must be the way to go (I lose Intellisense, don't I?) In practice, does this mean I should change all my Dim xlApp as Excel.Application to Dim xlApp as Object (and likewise for ppApp, olApp)? I have one class module that may be a problem and I'm not sure how to handle late binding in this respect. Here's the (fairly self-explanatory) code: '''=========ThisApplication.cls Option Explicit Public WithEvents oApp As Word.Application ------------------------------ Private Sub PsuedoAutoNew() Show_WOTTToolBar ViewSet "New" ZoomSet "New" End Sub Private Sub PsuedoAutoOpen() Show_WOTTToolBar ViewSet "Existing" ZoomSet "Existing" End Sub Should I change Public WithEvents oApp As Word.Application to ... As Object? Then write a Class_Initialize() and Class_Terminate()? And in the code module containing the AddIn's Autoexec: '''======= Support_Autoexec.bas Option Explicit Dim oAppClass As New ThisApplication 'i.e. new instance of class named 'ThisApplication' (see class module) Public oldNoOfOpenDocs As Long Public FirstNewDoc As Boolean Public Sub Autoexec '''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''' 'NB This only fires if this .dot(m) is a global template, i.e. in Word's Startup 'folder. It doesn't fire if this file is opened anywhere else ' THIS Autoexec fires AFTER the one in Normal.dot(m) ' ' and BEFORE the routines in the ThisApplication class module ' '''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''''' Set oAppClass.oApp = Word.Application oldNoOfOpenDocs = 0 FirstNewDoc = True "PUT ALL START-UP CODE HERE: WOTT Menu, WOTT Toolbar, WOTT Word 'settings,WOTT keyboard assignments etc. A_InitWOTT End Sub Thanks in advance for your invaludable advice Richard |
#4
|
||||
|
||||
Hi Richard,
What you can do is use early binding for the development, then convert to late binding once you're done. As you know, when using late binding, the calling app has no access to the called app's object model until the code is compiled. Thus, if you're automating Word from Excel with late binding, Excel has no way of knowing what wdBorderTop or wdLineStyleSingle, for example, are. If, having developed the code with early binding, you'd prefer to leave parameters like wdBorderTop and wdLineStyleSingle unchanged, you could declare them beforehand with code like: Const wdBorderTop As Long = -1 Const wdLineStyleSingle As Long = 1 This has the advantage that, even with late binding, you can continue to use expressions like: .Borders(wdBorderTop).LineStyle = wdLineStyleSingle which, of course, are much easier to interpret than: .Borders(-1).LineStyle = 1 Plus, you then don't have to go through your code and change every instance of 'wdLineStyleSingle' to '-1'. It also makes it easy to switch back & forth between early & late binding for code maintenance/enhancement.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
||||
|
||||
For more info on the benefits/drawbacks of early & late binding, see:
http://support.microsoft.com/kb/245115 http://word.mvps.org/FAQs/InterDev/EarlyvsLateBinding.htm For examples, see: http://www.exceltip.com/st/Basic_information_about_OLE_automation_using_VBA_i n_Microsoft_Excel/462.html http://forums.techguy.org/business-applications/1036615-solved-vba-search-replace-word.html
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#6
|
||||
|
||||
Quote:
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#7
|
|||
|
|||
Thanks Paul for all this sound advice.
On reflection I think I'll stick with early binding and import/replace the modules whenever necessary into the 2007 (.dotm) and 2003 (.dot) versions. Richard |
Tags |
2007, 2010, addin compatibility |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Problem suddenly developed with captions | Big Ry | Word | 1 | 01-15-2012 01:26 PM |
Copy/Paste from Paint to Word - There is a problem saving the file | one2three | Word | 1 | 10-26-2011 07:35 AM |
How to use .dotm template extension in MS Word? | dude444 | Word | 0 | 09-20-2010 09:34 AM |
Word 2007 crashes due to corrupt normal.dotm | stevebond001 | Word | 1 | 05-11-2010 10:49 AM |
Outlook 2007 addin problem with Visual Studio 2010 RC ? | johaseo | Outlook | 0 | 04-16-2010 02:49 PM |