How to Get Files.FullName

K

K

I have macro (see below) which put all kind of files names in ListBox1
from specified folder

Private Sub CommandButton1_Click()
Me.ListBox1.Clear
Dim Filename As String
Dim Foldername As String

Foldername = "C:\Documents and Settings\Files\"
Filename = Dir(Foldername)
Do Until Filename = ""
Me.ListBox1.AddItem (Filename)
Filename = Dir
Loop
End Sub

How can I get files full name or path in ListBox1. For example get
name like "C:\Documents and Settings\Files\Flag.pdf" instead of
"Flag.pdf". I know there is some modification needed in macro above
can any friend help.
 
C

Chip Pearson

Replace
Me.ListBox1.AddItem (Filename)
with
Me.ListBox1.AddItem FolderName & FileName

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)
 
K

K

Replace>Me.ListBox1.AddItem (Filename)

with
Me.ListBox1.AddItem FolderName & FileName

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
    Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLCwww.cpearson.com
(email on web site)






- Show quoted text -

thanks
 
K

K

Replace>Me.ListBox1.AddItem (Filename)

with
Me.ListBox1.AddItem FolderName & FileName

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
    Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLCwww.cpearson.com
(email on web site)






- Show quoted text -

Hi Chip I changed my macro little bit (see bleow) but I am getting
problem which that when I select on C: drive from Browse Folder then I
get result like C:\\jack.pdf but if select Folder in C: drive then it
work ok like then it comes C:\My Document\jack.pdf. Can you please
help that how can i make C:\\ to C:\ if i select on C: drive

Sub GetFiles()
Sheets(1).ListBox1.Clear
Dim Filename As String
Dim Foldername As String
Dim objShell
Dim objFolder

Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.browseforfolder(0, "CHOSE FOLDER:", 0, 17)

If (Not objFolder Is Nothing) Then
Foldername = objFolder.self.Path & "\"
Filename = Dir(Foldername)
Do Until Filename = ""
Sheets(1).ListBox1.AddItem (Foldername & Filename)
Filename = Dir
Loop
Sheets(1).ListBox1.AddItem ""
End If
End Sub
 
C

Chip Pearson

Change

Foldername = objFolder.self.Path & "\"

to

Foldername = objFolder.self.Path
If StrComp(Right(Foldername, 1), "\", vbBinaryCompare) <> 0 Then
Foldername = Foldername & "\"
End If



Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)'
 
K

K

Change

        Foldername = objFolder.self.Path & "\"

to

Foldername = objFolder.self.Path
If StrComp(Right(Foldername, 1), "\", vbBinaryCompare) <> 0 Then
        Foldername = Foldername & "\"
End If

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
    Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLCwww.cpearson.com
(email on web site)'







- Show quoted text -

Thanks Chip for your help
 

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