1

Windows 8 Machine (works): Microsoft Office Professional Plus 2013 Windows 10 Machine (doesn't work): Microsoft Office 365

Template (.dotm file) gets placed in Startup folder for Word. When I start Word I am presented with a blank screen. Clicking on "File" causes Word to exit immediately with no error message. The add-in has a module called MainModule and a class called WordApp. AutoExec fires up a loop which calls a dummy function.

MainModule:

'event processor class instance
 Dim myWordApp As WordApp
 Sub Register_Event_Handler()
   Set myWordApp.appWord = Word.Application
 End Sub

 'gets executed automatically
  Sub AutoExec()
    Set myWordApp = New WordApp
    Call MainProgram
  End Sub

Sub MainProgram()
   Register_Event_Handler
   Do While True
     testFunction
     DoEvents
     Loop
End Sub
'dummy function gets called in loop
Private Sub testFunction()
   Dim i As Integer
   i = 0
   i = i + 1
End Sub

WordApp class:

Public WithEvents appWord As Word.Application
'fires upon closing word
Private Sub appWord_DocumentBeforeClose(ByVal Doc As Document, Cancel As 
   Boolean)
    MsgBox "Closing"
End Sub
braX
  • 11,506
  • 5
  • 20
  • 33
  • Do you get an app crash event in the Windows event viewer? – Comintern Oct 12 '18 at 00:21
  • The `Do` loop test isn't making any sense to me: `Do While True`. While *what* is true? From what I can see, there's nothing to end the loop, meaning Word is going to run out of memory and crash. – Cindy Meister Oct 12 '18 at 05:05
  • Your autoexec is creating an infinite loop because it runs each time word starts and part of the auto exec is creating a new instance of the word app. You won't see these instances as you never set them to be visible. If you open task manager after running you code you will likely see lots of orphaned instances of Word. – freeflow Oct 12 '18 at 08:39
  • the class is not instanced in the loop. – Mihai Pruna Oct 12 '18 at 09:57
  • this is a stripped down example program, as the original contains proprietary data. Let's just say it is supposed to run for the duration of the Word session. – Mihai Pruna Oct 12 '18 at 09:58
  • As I said in my previous comment, you're in an infinite loop because the Do While loop never ends. You're not making a *comparison* that will let it end. That's using up available memory, so eventually Word crashes. But one thing is sure: you shouldn't have code that's supposed to run for as long as Word is open. That's what event handlers are for. Once you've started an event handler you shouldn't be trying to restart it, and restart it, ad infinitum. The fact that it - somehow - worked in a different environment was more a fault of that environment. Rethink what you're doing... – Cindy Meister Oct 13 '18 at 15:50
  • it worked fine with Office 13. Also, why would it crash on Office 365 only when trying to open a file from GUI. Starting a new document programmatically did not crash it. – Mihai Pruna Oct 15 '18 at 13:02
  • used recursive timer set at every 10ms. Example here: https://stackoverflow.com/questions/2319683/vba-macro-on-timer-style-to-run-code-every-set-number-of-seconds-i-e-120-secon – Mihai Pruna Oct 15 '18 at 13:03

0 Answers0