road runner
08-23-2012, 02:25 PM
I have experience with Excel VBA however i have recently been looking at Word, I am trying to create a document were a user can select a file from a user-form and a link will be created in a Form Field. So i don't have to rely on them typing in the correct path ( which they never do)
I have used VBA in excel before using GetOpenFilename, however Word does not support this. I have been looking around and can't find any suitable solution. I have pasted in a excel version of what i was trying to do. Can't remember were i found the code but it does exactly what i need it to do.
Private Sub ListFiles_Click()
Dim arrFiles
Dim I As Integer
arrFiles = Application.GetOpenFilename ' no usable in word
If IsArray(arrFiles) Then
lstFiles.Clear
lstFiles.List = arrFiles
End If
End Sub
Private Sub SelectFiles_Click()
Dim rng As Range
Dim I As Integer
Set rng = ActiveSheet.Range("A1") 'will be Form Filed
For I = 0 To lstFiles.ListCount - 1
If lstFiles.Selected(I) Then
rng.Value = lstFiles.List(I)
Set rng = rng.Offset(1, 0)
End If
Next I
End Sub
Thanks in advance for any help.
I have used VBA in excel before using GetOpenFilename, however Word does not support this. I have been looking around and can't find any suitable solution. I have pasted in a excel version of what i was trying to do. Can't remember were i found the code but it does exactly what i need it to do.
Private Sub ListFiles_Click()
Dim arrFiles
Dim I As Integer
arrFiles = Application.GetOpenFilename ' no usable in word
If IsArray(arrFiles) Then
lstFiles.Clear
lstFiles.List = arrFiles
End If
End Sub
Private Sub SelectFiles_Click()
Dim rng As Range
Dim I As Integer
Set rng = ActiveSheet.Range("A1") 'will be Form Filed
For I = 0 To lstFiles.ListCount - 1
If lstFiles.Selected(I) Then
rng.Value = lstFiles.List(I)
Set rng = rng.Offset(1, 0)
End If
Next I
End Sub
Thanks in advance for any help.