1
votes

As the title says, I've got a word template with macros that does not run properly in the new Word version from Office 2011 for MAC.

The thing which seems to not work properly is the following code:

Sub Document_New()
    myForm.Show
End Sub

The same is with Document_Open()

It doesn't seem to run this code on the Mac version.

Does anyone know why this won't work on the Mac, or if there's another way around to emulate the document_open/document_new function?

EDIT: The document is in the .dot format. And I tried to save it to .doc, then the Document_open() worked just fine, so it seems to not be working in the .dot format.. And Document_New() is not running in .doc since its not a new templatefile based on a document..

EDIT 2: Seems like it was a once only with the Document_open on .doc files. I cant make it work again. So weird! The only event I get working, and this is only when using the .doc file format, is Document_Close() - this works everytime...

EDIT 3: This is just getting weirder. I made a new .doc document with the following code:

Private Sub Document_Open()
    MsgBox ("BlaBlaBla")
End Sub

The code only runs if the Visual Basic Editor is open BEFORE I close the word file and try to open it again. If I close the Visual Basic Editor and then the word file, and then open the word file; The code is not run.

??

2
Your last edit makes all sense. There can only be one VB-run process, and when the VB editor is launched, you are able to control execution (the play/pause Stop buttons). So, if you where getting problems running the _Open() event with active VB-editor, that's the cause. All application VB events are suppressed, as it would mean an unintended code execution.jpinto3912

2 Answers

1
votes

All VB application events are suppressed if you have the VB-editor active, and the current project is not running. It is an intentional behavior, to prevent unwanted code execution, hence not debuggable.

I have used Workbook_Open() (in Excel), and I can only see it working on newly open Excel Xls (xlsm on 2010), from a non-open VB-editor Excel application. It will work if you have other doc/xls already open, but not if vb-editor is up.

Have you checked whether Macros are allowed? Do you have generated a certificate and setup your application as a trusted source?

0
votes

I'm having similar issues. It seems that MS removed support for the Document_New and Document_Open functions in the Word object model for Word 2011. See http://mac2.microsoft.com/vb/1033/Word/html/womscChangesBetweenWord2010and2011.htm