Here is a little of my code - I use 'doc' all over the place so it's defined in another module:
Global doc As Word.Document
For M = 1 To UBound(docMapper)
lblVent.Caption = ">>> Vent: Først undersøges links i dokumenter fra mappen: '" & docMapper(M) & "' i familiesystemets hovedmappe !"
folder = GetPathTo(CurrentDb.Name) & "" & docMapper(M) & ""
wdFn = Dir(folder & "*.docx")
Do While Len(wdFn) > 0
If stopFlag Then Exit Sub
lblTestet.Caption = testet & ", og heri findes: " & fundneLinkFiler & " linkede lokale filer !"
Set doc = Documents.Open(fileName:=folder & wdFn, Visible:=False)
If doc.Hyperlinks.Count > 0 Then
For hl = 1 To doc.Hyperlinks.Count
DoEvents
If InStr(1, doc.Hyperlinks(hl).Address, "http") = 0 And InStr(1, doc.Hyperlinks(hl).Address, "mailto:") = 0 Then
' så er det nget lokalt link og IKKE en 'mailadresse'
If extractFileExt(doc.Hyperlinks(hl).Address) <> "" Then
' så HAR der været en Ext på doc.Hyperlinks(hl).Address og så er det en FIL
' så er den interessant og skal gemmes
' Den finder OGSÅ nogle som IKKE er interessante for TESTEN, men hva' ... de forstyrre ikke !
DoCmd.SetWarnings False
' On Error Resume Next
' Den styrer åbenbart selv det med dubletter - der kommer INGEN meddelelse
DoCmd.RunSQL ("INSERT INTO [TESTING TempTable] VALUES ('" & doc.FullName & "', '" & extractFileName(doc.Hyperlinks(hl).Address) & "');")
On Error GoTo 0
DoCmd.SetWarnings True
fundneLinkFiler = fundneLinkFiler + 1
End If
End If
Next hl
End If
testet = testet + 1
doc.Close
Set doc = Nothing
wdFn = Dir()
DoEvents
Loop
Next M
End Sub
There is a lot of updating soem labels on the form - just to see how the test is running.
I often loose the server (the invisible Word instance) and found out that some of the problem is that the user starts up Word for another task while waiting on the test to finish - but unfortunately I often loose it just like that, I see NO reason at all
- that's why I want to run it sort of 'protected-mode' not affected by other instances of Word - but maybe it can't be done.