Returning Workbooks Names

egibberate

Board Regular
Joined
Jul 8, 2008
Messages
112
Hi,
I have a folder called 'VBA_Samples'

How do I write the code that will return the names of the Workbooks contained in the folder to Sheet2 of 'Referencing' Workbook

Thank you for your time and expertise.
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Quick and dirty.
Code:
Sub test()
    x = Dir("C:\VBA_Samples\*.xls")
    
    While x <> ""
        I = I + 1
        Range("A" & I) = x
        x = Dir()
    Wend
    
End Sub
 
Upvote 0
Thanks Norie
Is there a way I can automate the first line.
If the folder was copied to another computer it would be helpful if the code changed it to suit.
Thanks again for your help
 
Upvote 0
Hi,
I've got this far and I'm stumped (newbie I'm afaid)
So how do I get the list of files in to appear in Sheet2 of 'Referencing.xls'

Code:
Function fnstrwkbName() As String
'GET THIS FIRST OPENED WORKBOOK NAME
fnstrwkbName = Workbooks(1).Name
                                                                 
End Function
Function fnstrwkbPath() As String
'GET THIS FIRST OPENED WORKBOOK PATH
fnstrwkbPath = Workbooks(fnstrwkbName).Path
                                                                 
End Function
Function fnstrwkbFullName() As String
'GET THIS FIRST OPENED WORKBOOK FULL NAME
fnstrwkbFullName = Workbooks(fnstrwkbPath).FullName
                                                                 
End Function
Private Sub Worksheet_Activate()
x = Dir("fnstrwkbPath*.xls")

    While x <> ""
        I = I + 1
        .Range("A" & I) = x
        x = Dir()
     
    Wend
End Sub
 
Upvote 0
Like this perhaps?
Code:
x=Dir(ThisWorkbook.Path &"\*.xls)
And this.
Code:
Workbooks("Referencing.xls").Sheets("Sheet2").Range("A" & I) =x
 
Upvote 0
Well that's just a typo.:)
Code:
x=Dir(ThisWorkbook.Path & "\*.xls")
I deliberately put in there to see if you would spot it, honest.;)
 
Upvote 0
Norie, you are my hero.
I'm gonna toast your good health with a few beers.
Thank you very much for your help.
I'm very much obliged :biggrin:
 
Upvote 0

Forum statistics

Threads
1,214,905
Messages
6,122,175
Members
449,071
Latest member
cdnMech

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top