Får output i aktivt dokument istedet for "immediate window"
Jeg har følgende script, der virker perfekt, bortset fra, at jeg gerne vil outputtet i det aktive Word dokument. Nogen, der kan hjælpe?Sub Test7()
Dim Mydir As String
Dim MyFile As String
Dim Counter As Long
'Create a dynamic array variable, and then declare its initial size
Dim DirectoryListArray() As String
ReDim DirectoryListArray(1000)
'Loop through all the files in the directory by using Dir$ function -
Dim mypath As String
mypath = ActiveDocument.Path
MyFile = Dir$(mypath & "\*.*")
Do While MyFile <> ""
DirectoryListArray(Counter) = MyFile
MyFile = Dir$
Counter = Counter + 1
Loop
'Reset the size of the array without losing its values by using Redim Preserve
ReDim Preserve DirectoryListArray(Counter - 1)
'To prove it worked you could run the following:
For Counter = 0 To UBound(DirectoryListArray)
'Debug.Print writes the results to the Immediate window (press Ctrl + G to view it)'
Debug.Print DirectoryListArray(Counter)
Next Counter
End Sub