Add documents via listbox

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.
 
H

Helmut Weber

Hi,
Question: How do I get only the filename
I have been unable to retrieve only the filename without performing
string functions to strip out the file name.

String manipulation is the core of text processing.

Nothing wrong with it and no secret stuff.

Dim s As String
s = "h:\this\and\that\and\more\mydoc.doc"
s = StrReverse(s)
s = Left(s, InStr(s, "\") - 1)
s = StrReverse(s)
MsgBox s


Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
J

JonSteng

Thank you Helmut Weber, advice taken and appreciated. Clean, versital and
works like a charm.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top