Carles
Carles

Reputation: 68

VBA code stops whenever I open a document

First of all sorry for posting this, I know it's probably duplicated from this post, I tried to post it as an edit but it got rejected and I can't comment because I don't have 50 reputation, also this is not a proper answer. Hope this helps to get a better understanding of the problem and more attention.

I work in a company that uses VBA and we've been using Documents.Open for a long time and it never gave me any problems, until now. The problem seems rather random, as not many clients have this, but it's turning more consistent now mainly with Office 365. Maybe it's due to an actualization?

Whenever I do Documents.Open the requested document will open, but anything that comes after that won't be executed. It can be as simple as:

Sub Test()
    Documents.Open(filename)
    MsgBox "Hi"
End Sub

And the message box will never be shown. I've also tried this, as I found something related in other forums:

Sub Test()
    Dim doc as Document
    set doc = Documents.Open(filename)
    MsgBox "Hi"
End Sub

I've even tried the old open WordBasic.FileOpen(). Nothing helps, code stops executing after opening the document. In a desperated attempt at making this work, I've created a COM dll that opens a document, with a message box in the dll and in VBA after the dll has done it's part. The dll functions properly but as soon as it gets back to VBA the code stops and it doesn't show the message box.

I've done some research and it has nothing to do with the known shift-key bug since I can run the example code by pressing the play button, so no keys are being pressed when the document opens.

Then I tried to work with the AutoOpen event as seen in this other post and by debbuging I've realized that the PseudoAutoOpen event it's never called in the computers with the problem.

Also made sure that everything it's in the trusted documents location and that the macros are enabled, as this other post said: Word 2013 VBA - opening document aborts macro

UPDATE

I've found out accidentally while debugging, that if I run the example macro twice, the second time (with the targeted document opened) it works as intended.

I'm starting to lose my mind over this.

Upvotes: 3

Views: 1203

Answers (2)

Willems Davy
Willems Davy

Reputation: 105

I've gotten report from MVP's at the forums of microsoft that they did a server sided change to a configuration file that word downloads during startup of word. The change makes it so, so that the (new) problematic code causing (my documents.add) problem gets disabled.

I just tested it with a client that had the problem and were we downgraded the office version to the previous build and now the problem as far i could tell seems to be solved.

It could be if you update your office version again it also works with you. Potentially if the problem still occurs the 1st time you need to close word wait a bit and start again.

Maybe it is now also fixed for the documents.open problem with this (server sided) change.

More info in original discution here https://answers.microsoft.com/en-us/msoffice/forum/msoffice_word-msoffice_custom-mso_2016/1807-build-1032520082-is-causing-vba-problems-with/538e8c3c-355e-47a7-9e3f-58cf04902c10

Upvotes: 0

m.swiss
m.swiss

Reputation: 104

The problem seems to be with the 1807 Build 10325.20082 update.

Restoring to an earlier build (9330.2087) fixed the problem for me:

https://support.microsoft.com/en-us/help/2770432/how-to-revert-to-an-earlier-version-of-office-2013-or-office-2016-clic

Upvotes: 1

Related Questions