0
votes

I'm running pretty simple VBA in Word:

Sub Something

On Error GoTo prob

Dim d As Document

Set d = Documents.Open(FileName:="c:\ajb files\test.docx")

'this should run if macro succeeds
MsgBox "ok"
Exit Sub

'this should run if macro fails
prob:
MsgBox "prob"

End Sub

This macro opens the Word document then stops (without triggering an error message).

I tried running the same macro in Word 2010 and it works fine. I haven't got an Acer laptop, or any weird anti-virus or other software running. I removed all Word add-ins, and the problem still happens.

If I go straight into Word and run this macro, it works fine. The problem comes when I first run a macro in Access which tries to run this code through Word VBA, and seizes up on the line above. If I then try to run the macro without first closing Word, it hangs after opening the document.

2
Your macro is ok and works ok in Word 2013. Don't you have any add-ins installed which could have influence on your code?Kazimierz Jawor
My macro definitely isn't OK on my computer! I disabled all of my add-ins, and I still have the problem. However, it does seem to be related to running VBA from within Access, so I've edited my question, which might have been over-simplified.Andy Brown
you have edited or you are going to edit it? what about this Access??Kazimierz Jawor
Sorry - have edited now.Andy Brown

2 Answers

0
votes

OK, I've solved the problem. The Access VBA macro was opening a Word template which wasn't in a trusted location. Somewhere along the line this was causing it to hang. I've added the Word template folder to my list of trusted locations and it seems to have solved the problem.

0
votes

Check out this thread: VBA code stops after Documents.Open

I have the exact same problem and I thought I found a fix today when I set the windows security for the folder holding the file allow anything and everything to edit the folder. (The location was already trusted in Word). It solved the problem in ONE location, but the exact same fix, plus making sure the location was trusted, did NOT work in two other places.

I am going to try rolling back my Word version per the instructions in the thread I linked.