RoundRocket
New Member
- Joined
- Nov 28, 2013
- Messages
- 24
Hi, i have the vba code below which lists file names in a chosen folder in the first column of an excel worksheet (worksheet 2 in this case), does anyone know how i can adapt this code so that it doesnt pick up and report on any files that begin with a '~$' ?
Occasionally it picks up files beginning like this, for example: ~$Doc1.docx
If anyone knows what these file types are?! please let me know. I think they are temporary files.. but not sure. thank you.
Sub Button3_Click()
Call ListDocumentFiles
End Sub
Sub ListDocumentFiles()
Dim fso As New FileSystemObject
Dim fle As file
Dim fldr As folder
Dim i As Integer
Call ThisWorkbook.Worksheets(2).Range("A:A").Clear
With Application.FileDialog(msoFileDialogFolderPicker)
Call .Show
Set fldr = fso.GetFolder(.SelectedItems(1))
End With
For Each fle In fldr.Files
If InStr(1, fle.Name, ".", vbTextCompare) <> 0 Then
Let i = i + 1
Let ThisWorkbook.Worksheets(2).Cells(i, 1) = fle.Name
End If
Next
MsgBox ("Search complete")
Set fle = Nothing
Set fldr = Nothing
Set fso = Nothing
End Sub
Occasionally it picks up files beginning like this, for example: ~$Doc1.docx
If anyone knows what these file types are?! please let me know. I think they are temporary files.. but not sure. thank you.
Sub Button3_Click()
Call ListDocumentFiles
End Sub
Sub ListDocumentFiles()
Dim fso As New FileSystemObject
Dim fle As file
Dim fldr As folder
Dim i As Integer
Call ThisWorkbook.Worksheets(2).Range("A:A").Clear
With Application.FileDialog(msoFileDialogFolderPicker)
Call .Show
Set fldr = fso.GetFolder(.SelectedItems(1))
End With
For Each fle In fldr.Files
If InStr(1, fle.Name, ".", vbTextCompare) <> 0 Then
Let i = i + 1
Let ThisWorkbook.Worksheets(2).Cells(i, 1) = fle.Name
End If
Next
MsgBox ("Search complete")
Set fle = Nothing
Set fldr = Nothing
Set fso = Nothing
End Sub