While coding and extending the functionality of my Sub there are sadly arising some errors - e.g. a runtime error - but it could be any error...
The main topic of my question is that for me it's impossible to open that specific Word document (Test.docx
) by hand (clicking on it in the explorer).
I have found one solution but this one is annoying, because I have to restart my computer and this is time consuming... and I hope there exists a more elegant solution that you can share with me.
So many thanks in advance!
Now my code with an provoked error...
Sub GetInfoOutOfWordDocument()
'Init
Dim appWord As Word.Application
Dim document As Word.Document
Dim strFolder As String
Dim strFile As String
Dim MyArray() As Variant ' for arising the error
' Select the word document
strFolder = "C:\Users\"
strFile = Dir(strFolder & "Test.docx", vbNormal)
' Open the word document
Set appWord = CreateObject("Word.Application")
Set document = appWord.Documents.Open( _
FileName:=strFolder & "\" & strFile, AddToRecentFiles:=False, ReadOnly:=False, Visible:=False)
' Getting the needed information out of your Word document...
' Now the error occurs - e.g. runtime error
MyArray(1)=5
' Problem: The above opened Word document isn't closed properly and therefore
I'm not able to open the specific Word document by hand
dokument.Close wdDoNotSaveChanges
appWord.Quit
Set document = Nothing
Set appWord = Nothing
End Sub