Converting a code to a UDF.

omairhe

Well-known Member
Joined
Mar 26, 2009
Messages
2,040
Office Version
  1. 2019
Platform
  1. Windows
Hello all,

The following code will extract filenames in a sheet called "File Extraction"

VBA Code:
Sub Auto_Open()
  Dim FileSystem As Object
  Dim HostFolder As String
    HostFolder = "C:\Users\e314704\Desktop\LCST Gain Share\Reports"
    
  Set FileSystem = CreateObject("Scripting.FileSystemObject")
  DoFolder FileSystem.getFolder(HostFolder)
End Sub
Sub DoFolder(Folder)
  Dim SubFolder
  For Each SubFolder In Folder.SubFolders
    DoFolder SubFolder
  Next
  i = Sheets("File Extraction").Cells(Rows.Count, 1).End(xlUp).Row + 2
  Dim File
  For Each File In Folder.Files
    Sheets("File Extraction").Hyperlinks.Add Anchor:=Cells(i, 1), Address:= _
        File.Path, TextToDisplay:=File.Name
    i = i + 1
  Next
End Sub


However I need it to run as a UDF.

Anyone? Will appreciate. . .
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Why do you want to make this a UDF, it is not the sort of function you want to use in a cell on worksheet??
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

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