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

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
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,223,234
Messages
6,170,891
Members
452,366
Latest member
TePunaBloke

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