Private Sub Command0_Click()
Dim DocN As String
Dim LWordDoc As String
Dim oApp As Object
Dim oDoc As Object
Dim oVariable As Variable
DocN = "Demo use of variables.docx"
'Path to the word document
LWordDoc = "C:\Temp\20230411 test\" & DocN
If Dir(LWordDoc) = "" Then
MsgBox "Document not found."
Else
'Create an instance of MS Word
Set oApp = CreateObject(Class:="Word.Application")
oApp.Visible = True
'Open the Document
Set oDoc = oApp.Documents.Open(Filename:=LWordDoc)
End If
Call dump_to_file("")
For Each oVariable In oDoc.Variables
Call append_to_file(oVariable.Name & " : " & oVariable.Value)
Next oVariable
' Close doc
oDoc.Close SaveChanges:=True ' True to save, False to close without saving
Set oDoc = Nothing
Set oApp = Nothing
MsgBox "done"
End Sub
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter