J
JonSteng
I need to insert documents, at either the front or end of the open document,
from either a network drive or user hard drive. I would like to make these
files available to users via a listbox on a form.
I have been able to use file scripting object to browse to the files and add
them to the list box using the following code:
Sub GetFiles()
Dim fs, f, f1, fc, fn, s
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder("C:\Documents")
Set fc = f.Files
For Each f1 In fc
' fn = f1.FileName
If InStr(1, f1.Name, "boilerplate", vbTextCompare) Then
Set fn = fs.GetFile(f1)
lbBoilerplates.AddItem (fn)
End If
Next
Set fs = Nothing
End Sub
This is all good, however: The list box is populated with the entire path
and file name. What I would like to do is list only the file name.
When the user selects desired documents (could be 1 or many) I would then
insert the files into the document.
Question: How do I get only the filename without the path for populating the
listbox? I have been unable to retrieve only the filename without performing
string functions to strip out the file name.
Any suggestions greatly appreciated.
Thank you.
from either a network drive or user hard drive. I would like to make these
files available to users via a listbox on a form.
I have been able to use file scripting object to browse to the files and add
them to the list box using the following code:
Sub GetFiles()
Dim fs, f, f1, fc, fn, s
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder("C:\Documents")
Set fc = f.Files
For Each f1 In fc
' fn = f1.FileName
If InStr(1, f1.Name, "boilerplate", vbTextCompare) Then
Set fn = fs.GetFile(f1)
lbBoilerplates.AddItem (fn)
End If
Next
Set fs = Nothing
End Sub
This is all good, however: The list box is populated with the entire path
and file name. What I would like to do is list only the file name.
When the user selects desired documents (could be 1 or many) I would then
insert the files into the document.
Question: How do I get only the filename without the path for populating the
listbox? I have been unable to retrieve only the filename without performing
string functions to strip out the file name.
Any suggestions greatly appreciated.
Thank you.