View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.misc
Claus Busch Claus Busch is offline
external usenet poster
 
Posts: 3,872
Default Stripping out text?

Hi Terry,

Am Thu, 14 Dec 2017 14:02:42 +0100 schrieb Claus Busch:

Sub Test()
Dim FSO As Object
Dim objFolder As Object, objSubFolder As Object, objFile As Object
Dim MyPath As String
Dim i As Long


sorry, the folder and subfolder names are missing into the code.
Try:

Sub Test()
Dim FSO As Object
Dim objFolder As Object, objSubFolder As Object, objFile As Object
Dim MyPath As String
Dim i As Long

Set FSO = CreateObject("scripting.fileSystemobject")
MyPath = Range("A1").Value
Set objFolder = FSO.getfolder(MyPath)

i = 2
For Each objFile In objFolder.Files
ActiveSheet.Hyperlinks.Add _
anchor:=Cells(i, "F"), _
Address:="file:///" & MyPath & objFolder.Name & _
"\" & objFile.Name, _
TextToDisplay:=objFile.Name
Cells(i, "G") = Format(objFile.Size / 1024 ^ 3, "0.000") & " GB"
i = i + 1
Next
On Error Resume Next
For Each objSubFolder In objFolder.subfolders
For Each objFile In objSubFolder.Files
ActiveSheet.Hyperlinks.Add _
anchor:=Cells(i, "F"), _
Address:="file:///" & MyPath & objSubFolder.Name & _
"\" & objFile.Name, _
TextToDisplay:=objFile.Name
Cells(i, "G") = Format(objFile.Size / 1024 ^ 3, "0.000") & " GB"
i = i + 1
Next
Next
End Sub


Regards
Claus B.
--
Windows10
Office 2016