|
|
Below is a function that will allow you to get the address of a text file using VBA in Microsoft Word
Function GetOpenFileName() As String
'Returns the folder and/or filename to a single user selected file
Dim strFileName As String, strPathName As String
With Application.Dialogs(wdDialogFileOpen)
.Name = "*.txt"
On Error GoTo MultipleFilesSelected
If .Display = -1 Then
strFileName = .Name
End If
On Error GoTo 0
End With
On Error GoTo 0
'Removes any "-characters
If InStr(1, strFileName, " ", vbTextCompare) > 0 Then
strFileName = Mid$(strFileName, 2, Len(strFileName) - 2)
End If
strPathName = CurDir & Application.PathSeparator
GetOpenFileName = strPathName & strFileName
MultipleFilesSelected:
End Function
Below is VBA code that will allow you to get the address of a text file using VBA in Microsoft Excel
FileName1 = Application.GetOpenFilename("Text Files (*.txt), *.txt")