Find folders that contain a file (VBA)
I have a question regarding some VBA coding. I have an Excel spreadsheet with rows that each contain an identification number (e.g. ABC0123456ABC). I also have a folder with subfolders that have a name similar to the identification number from the Excel file. However, some of these subfolders contain more files (all pdfs). I would like to know which folders contain files (and which do not).
Thus, I would like to search all folders that contain files with the names that are taken from the excel file.
How would I best do this?
excel vba find folder
|
show 1 more comment
I have a question regarding some VBA coding. I have an Excel spreadsheet with rows that each contain an identification number (e.g. ABC0123456ABC). I also have a folder with subfolders that have a name similar to the identification number from the Excel file. However, some of these subfolders contain more files (all pdfs). I would like to know which folders contain files (and which do not).
Thus, I would like to search all folders that contain files with the names that are taken from the excel file.
How would I best do this?
excel vba find folder
You could use the FileSystemObject . A google search might throw up examples
– Harassed Dad
Nov 23 '18 at 9:37
Welcome to SO. How would I best do this? You could code some loops to check folders and subfolders and find what you are looking for.
– Foxfire And Burns And Burns
Nov 23 '18 at 9:53
Thank you for your replies! I'm relatively new to VBA so where would I start? I found some code on Google that comes close to my solution but I can't seem to make it suit my dataset and folders
– jtsbattle
Nov 23 '18 at 10:19
@jtsbattle So for each identification number in your Excel file, you want to find all subfolders (in a particular folder) which contain the identification number in their name -- and then for each of these found subfolders (which do contain the identification number in their name), you want to do what? Check if each subfolder contains PDF files? Check if each subfolder contains any files?
– chillin
Nov 23 '18 at 11:14
@chillin I have a list of ID numbers in an Excel file and I have a directory containing a lot of folders that have the same numbers as the ID numbers in the Excel file. So for every ID number in the Excel file, there is a folder available as well. However, some of these folders have files and some are empty. For each ID number in Excel, I would like to know which folders are empty (and thus also which are not). I hope this clarifies it!
– jtsbattle
Nov 23 '18 at 14:23
|
show 1 more comment
I have a question regarding some VBA coding. I have an Excel spreadsheet with rows that each contain an identification number (e.g. ABC0123456ABC). I also have a folder with subfolders that have a name similar to the identification number from the Excel file. However, some of these subfolders contain more files (all pdfs). I would like to know which folders contain files (and which do not).
Thus, I would like to search all folders that contain files with the names that are taken from the excel file.
How would I best do this?
excel vba find folder
I have a question regarding some VBA coding. I have an Excel spreadsheet with rows that each contain an identification number (e.g. ABC0123456ABC). I also have a folder with subfolders that have a name similar to the identification number from the Excel file. However, some of these subfolders contain more files (all pdfs). I would like to know which folders contain files (and which do not).
Thus, I would like to search all folders that contain files with the names that are taken from the excel file.
How would I best do this?
excel vba find folder
excel vba find folder
asked Nov 23 '18 at 9:22
jtsbattlejtsbattle
31
31
You could use the FileSystemObject . A google search might throw up examples
– Harassed Dad
Nov 23 '18 at 9:37
Welcome to SO. How would I best do this? You could code some loops to check folders and subfolders and find what you are looking for.
– Foxfire And Burns And Burns
Nov 23 '18 at 9:53
Thank you for your replies! I'm relatively new to VBA so where would I start? I found some code on Google that comes close to my solution but I can't seem to make it suit my dataset and folders
– jtsbattle
Nov 23 '18 at 10:19
@jtsbattle So for each identification number in your Excel file, you want to find all subfolders (in a particular folder) which contain the identification number in their name -- and then for each of these found subfolders (which do contain the identification number in their name), you want to do what? Check if each subfolder contains PDF files? Check if each subfolder contains any files?
– chillin
Nov 23 '18 at 11:14
@chillin I have a list of ID numbers in an Excel file and I have a directory containing a lot of folders that have the same numbers as the ID numbers in the Excel file. So for every ID number in the Excel file, there is a folder available as well. However, some of these folders have files and some are empty. For each ID number in Excel, I would like to know which folders are empty (and thus also which are not). I hope this clarifies it!
– jtsbattle
Nov 23 '18 at 14:23
|
show 1 more comment
You could use the FileSystemObject . A google search might throw up examples
– Harassed Dad
Nov 23 '18 at 9:37
Welcome to SO. How would I best do this? You could code some loops to check folders and subfolders and find what you are looking for.
– Foxfire And Burns And Burns
Nov 23 '18 at 9:53
Thank you for your replies! I'm relatively new to VBA so where would I start? I found some code on Google that comes close to my solution but I can't seem to make it suit my dataset and folders
– jtsbattle
Nov 23 '18 at 10:19
@jtsbattle So for each identification number in your Excel file, you want to find all subfolders (in a particular folder) which contain the identification number in their name -- and then for each of these found subfolders (which do contain the identification number in their name), you want to do what? Check if each subfolder contains PDF files? Check if each subfolder contains any files?
– chillin
Nov 23 '18 at 11:14
@chillin I have a list of ID numbers in an Excel file and I have a directory containing a lot of folders that have the same numbers as the ID numbers in the Excel file. So for every ID number in the Excel file, there is a folder available as well. However, some of these folders have files and some are empty. For each ID number in Excel, I would like to know which folders are empty (and thus also which are not). I hope this clarifies it!
– jtsbattle
Nov 23 '18 at 14:23
You could use the FileSystemObject . A google search might throw up examples
– Harassed Dad
Nov 23 '18 at 9:37
You could use the FileSystemObject . A google search might throw up examples
– Harassed Dad
Nov 23 '18 at 9:37
Welcome to SO. How would I best do this? You could code some loops to check folders and subfolders and find what you are looking for.
– Foxfire And Burns And Burns
Nov 23 '18 at 9:53
Welcome to SO. How would I best do this? You could code some loops to check folders and subfolders and find what you are looking for.
– Foxfire And Burns And Burns
Nov 23 '18 at 9:53
Thank you for your replies! I'm relatively new to VBA so where would I start? I found some code on Google that comes close to my solution but I can't seem to make it suit my dataset and folders
– jtsbattle
Nov 23 '18 at 10:19
Thank you for your replies! I'm relatively new to VBA so where would I start? I found some code on Google that comes close to my solution but I can't seem to make it suit my dataset and folders
– jtsbattle
Nov 23 '18 at 10:19
@jtsbattle So for each identification number in your Excel file, you want to find all subfolders (in a particular folder) which contain the identification number in their name -- and then for each of these found subfolders (which do contain the identification number in their name), you want to do what? Check if each subfolder contains PDF files? Check if each subfolder contains any files?
– chillin
Nov 23 '18 at 11:14
@jtsbattle So for each identification number in your Excel file, you want to find all subfolders (in a particular folder) which contain the identification number in their name -- and then for each of these found subfolders (which do contain the identification number in their name), you want to do what? Check if each subfolder contains PDF files? Check if each subfolder contains any files?
– chillin
Nov 23 '18 at 11:14
@chillin I have a list of ID numbers in an Excel file and I have a directory containing a lot of folders that have the same numbers as the ID numbers in the Excel file. So for every ID number in the Excel file, there is a folder available as well. However, some of these folders have files and some are empty. For each ID number in Excel, I would like to know which folders are empty (and thus also which are not). I hope this clarifies it!
– jtsbattle
Nov 23 '18 at 14:23
@chillin I have a list of ID numbers in an Excel file and I have a directory containing a lot of folders that have the same numbers as the ID numbers in the Excel file. So for every ID number in the Excel file, there is a folder available as well. However, some of these folders have files and some are empty. For each ID number in Excel, I would like to know which folders are empty (and thus also which are not). I hope this clarifies it!
– jtsbattle
Nov 23 '18 at 14:23
|
show 1 more comment
1 Answer
1
active
oldest
votes
I think you could modify this to your needs;
If i have a spreadsheet like this (data in range B1:B3);
where each row represents a sub-folder and you want to know if you have a file in each of these sub-folders
Then you can use this code. It will write whether there is a file which contains the same name as shown in column B to column C.
Public Sub FindFiles()
Dim myParentFolderLoc As String
Dim curValue As String
Dim myCell As Range
Dim myRange As Range
Dim outputRange As Range
' Change these to your range/Folder Location;
Set myRange = Sheet1.Range("B1:B3")
Set outputRange = Sheet1.Range("B1:C3") ' note the inclusion of the column to which i am writing
myParentFolderLoc = "C:Example Folder"
' Loop through your excel cells
For Each myCell In myRange.Cells
If isFileInFolder(myParentFolderLoc, myCell.Value) Then
myCell.Offset(0, 1).Value = "Files Exists"
Else
myCell.Offset(0, 1).Value = "No Files Exists"
End If
Next myCell
' Export to Txt
ExportRangeToTxt outputRange
End Sub
' Loop through the folder and see if a file contains the string
Private Function isFileInFolder(folderLocation As String, folderName As String) As Boolean
Dim i As Integer
i = 0
file = Dir(folderLocation & folderName & "")
While (file <> "")
i = i + 1
file = Dir
Wend
If i > 0 Then
isFileInFolder = True
Else
isFileInFolder = False
End If
End Function
Private Sub ExportRangeToTxt(myRange As Range)
Dim myFile As String
Dim rng As Range
Dim cellValue As Variant
Dim i As Integer
Dim j As Integer
myFile = Application.DefaultFilePath & "output.txt"
Set rng = myRange
Open myFile For Output As #1
For i = 1 To rng.Rows.Count
For j = 1 To rng.Columns.Count
cellValue = rng.Cells(i, j).Value
If j = rng.Columns.Count Then
Write #1, cellValue
Else
Write #1, cellValue,
End If
Next j
Next i
Close #1
MsgBox "Text Export Complete - Check the file at: " & myFile
End Sub
This will export a file to the default file path of the application - the message box will tell you where this is.
Remember to update the ranges as shown for the example to include all your sub-folders. I could do this automatically but i dont want to make any assumptions having not seen your data.
Thanks! However, the files inside the folders do not have the same name as the folder. Thus: I have a list of values in Excel with identification numbers (e.g. ABCDE1234) and I have a list folders that are named the same. However, some of these folders contain files and some don't. I only need to known which folders contain files or which are empty
– jtsbattle
Nov 23 '18 at 14:06
Ideally, the results could be saved in a .txt file
– jtsbattle
Nov 23 '18 at 14:32
so what is in your excel sheet is a folder - and you need to know what folders have files in them? and they are all subfolders underneath a parent folder?
– James Cooke
Nov 23 '18 at 14:47
Yes that's exactly what I need!
– jtsbattle
Nov 23 '18 at 15:11
go on then.. its friday I will add the .txt thing.
– James Cooke
Nov 23 '18 at 15:12
|
show 3 more comments
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53443778%2ffind-folders-that-contain-a-file-vba%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I think you could modify this to your needs;
If i have a spreadsheet like this (data in range B1:B3);
where each row represents a sub-folder and you want to know if you have a file in each of these sub-folders
Then you can use this code. It will write whether there is a file which contains the same name as shown in column B to column C.
Public Sub FindFiles()
Dim myParentFolderLoc As String
Dim curValue As String
Dim myCell As Range
Dim myRange As Range
Dim outputRange As Range
' Change these to your range/Folder Location;
Set myRange = Sheet1.Range("B1:B3")
Set outputRange = Sheet1.Range("B1:C3") ' note the inclusion of the column to which i am writing
myParentFolderLoc = "C:Example Folder"
' Loop through your excel cells
For Each myCell In myRange.Cells
If isFileInFolder(myParentFolderLoc, myCell.Value) Then
myCell.Offset(0, 1).Value = "Files Exists"
Else
myCell.Offset(0, 1).Value = "No Files Exists"
End If
Next myCell
' Export to Txt
ExportRangeToTxt outputRange
End Sub
' Loop through the folder and see if a file contains the string
Private Function isFileInFolder(folderLocation As String, folderName As String) As Boolean
Dim i As Integer
i = 0
file = Dir(folderLocation & folderName & "")
While (file <> "")
i = i + 1
file = Dir
Wend
If i > 0 Then
isFileInFolder = True
Else
isFileInFolder = False
End If
End Function
Private Sub ExportRangeToTxt(myRange As Range)
Dim myFile As String
Dim rng As Range
Dim cellValue As Variant
Dim i As Integer
Dim j As Integer
myFile = Application.DefaultFilePath & "output.txt"
Set rng = myRange
Open myFile For Output As #1
For i = 1 To rng.Rows.Count
For j = 1 To rng.Columns.Count
cellValue = rng.Cells(i, j).Value
If j = rng.Columns.Count Then
Write #1, cellValue
Else
Write #1, cellValue,
End If
Next j
Next i
Close #1
MsgBox "Text Export Complete - Check the file at: " & myFile
End Sub
This will export a file to the default file path of the application - the message box will tell you where this is.
Remember to update the ranges as shown for the example to include all your sub-folders. I could do this automatically but i dont want to make any assumptions having not seen your data.
Thanks! However, the files inside the folders do not have the same name as the folder. Thus: I have a list of values in Excel with identification numbers (e.g. ABCDE1234) and I have a list folders that are named the same. However, some of these folders contain files and some don't. I only need to known which folders contain files or which are empty
– jtsbattle
Nov 23 '18 at 14:06
Ideally, the results could be saved in a .txt file
– jtsbattle
Nov 23 '18 at 14:32
so what is in your excel sheet is a folder - and you need to know what folders have files in them? and they are all subfolders underneath a parent folder?
– James Cooke
Nov 23 '18 at 14:47
Yes that's exactly what I need!
– jtsbattle
Nov 23 '18 at 15:11
go on then.. its friday I will add the .txt thing.
– James Cooke
Nov 23 '18 at 15:12
|
show 3 more comments
I think you could modify this to your needs;
If i have a spreadsheet like this (data in range B1:B3);
where each row represents a sub-folder and you want to know if you have a file in each of these sub-folders
Then you can use this code. It will write whether there is a file which contains the same name as shown in column B to column C.
Public Sub FindFiles()
Dim myParentFolderLoc As String
Dim curValue As String
Dim myCell As Range
Dim myRange As Range
Dim outputRange As Range
' Change these to your range/Folder Location;
Set myRange = Sheet1.Range("B1:B3")
Set outputRange = Sheet1.Range("B1:C3") ' note the inclusion of the column to which i am writing
myParentFolderLoc = "C:Example Folder"
' Loop through your excel cells
For Each myCell In myRange.Cells
If isFileInFolder(myParentFolderLoc, myCell.Value) Then
myCell.Offset(0, 1).Value = "Files Exists"
Else
myCell.Offset(0, 1).Value = "No Files Exists"
End If
Next myCell
' Export to Txt
ExportRangeToTxt outputRange
End Sub
' Loop through the folder and see if a file contains the string
Private Function isFileInFolder(folderLocation As String, folderName As String) As Boolean
Dim i As Integer
i = 0
file = Dir(folderLocation & folderName & "")
While (file <> "")
i = i + 1
file = Dir
Wend
If i > 0 Then
isFileInFolder = True
Else
isFileInFolder = False
End If
End Function
Private Sub ExportRangeToTxt(myRange As Range)
Dim myFile As String
Dim rng As Range
Dim cellValue As Variant
Dim i As Integer
Dim j As Integer
myFile = Application.DefaultFilePath & "output.txt"
Set rng = myRange
Open myFile For Output As #1
For i = 1 To rng.Rows.Count
For j = 1 To rng.Columns.Count
cellValue = rng.Cells(i, j).Value
If j = rng.Columns.Count Then
Write #1, cellValue
Else
Write #1, cellValue,
End If
Next j
Next i
Close #1
MsgBox "Text Export Complete - Check the file at: " & myFile
End Sub
This will export a file to the default file path of the application - the message box will tell you where this is.
Remember to update the ranges as shown for the example to include all your sub-folders. I could do this automatically but i dont want to make any assumptions having not seen your data.
Thanks! However, the files inside the folders do not have the same name as the folder. Thus: I have a list of values in Excel with identification numbers (e.g. ABCDE1234) and I have a list folders that are named the same. However, some of these folders contain files and some don't. I only need to known which folders contain files or which are empty
– jtsbattle
Nov 23 '18 at 14:06
Ideally, the results could be saved in a .txt file
– jtsbattle
Nov 23 '18 at 14:32
so what is in your excel sheet is a folder - and you need to know what folders have files in them? and they are all subfolders underneath a parent folder?
– James Cooke
Nov 23 '18 at 14:47
Yes that's exactly what I need!
– jtsbattle
Nov 23 '18 at 15:11
go on then.. its friday I will add the .txt thing.
– James Cooke
Nov 23 '18 at 15:12
|
show 3 more comments
I think you could modify this to your needs;
If i have a spreadsheet like this (data in range B1:B3);
where each row represents a sub-folder and you want to know if you have a file in each of these sub-folders
Then you can use this code. It will write whether there is a file which contains the same name as shown in column B to column C.
Public Sub FindFiles()
Dim myParentFolderLoc As String
Dim curValue As String
Dim myCell As Range
Dim myRange As Range
Dim outputRange As Range
' Change these to your range/Folder Location;
Set myRange = Sheet1.Range("B1:B3")
Set outputRange = Sheet1.Range("B1:C3") ' note the inclusion of the column to which i am writing
myParentFolderLoc = "C:Example Folder"
' Loop through your excel cells
For Each myCell In myRange.Cells
If isFileInFolder(myParentFolderLoc, myCell.Value) Then
myCell.Offset(0, 1).Value = "Files Exists"
Else
myCell.Offset(0, 1).Value = "No Files Exists"
End If
Next myCell
' Export to Txt
ExportRangeToTxt outputRange
End Sub
' Loop through the folder and see if a file contains the string
Private Function isFileInFolder(folderLocation As String, folderName As String) As Boolean
Dim i As Integer
i = 0
file = Dir(folderLocation & folderName & "")
While (file <> "")
i = i + 1
file = Dir
Wend
If i > 0 Then
isFileInFolder = True
Else
isFileInFolder = False
End If
End Function
Private Sub ExportRangeToTxt(myRange As Range)
Dim myFile As String
Dim rng As Range
Dim cellValue As Variant
Dim i As Integer
Dim j As Integer
myFile = Application.DefaultFilePath & "output.txt"
Set rng = myRange
Open myFile For Output As #1
For i = 1 To rng.Rows.Count
For j = 1 To rng.Columns.Count
cellValue = rng.Cells(i, j).Value
If j = rng.Columns.Count Then
Write #1, cellValue
Else
Write #1, cellValue,
End If
Next j
Next i
Close #1
MsgBox "Text Export Complete - Check the file at: " & myFile
End Sub
This will export a file to the default file path of the application - the message box will tell you where this is.
Remember to update the ranges as shown for the example to include all your sub-folders. I could do this automatically but i dont want to make any assumptions having not seen your data.
I think you could modify this to your needs;
If i have a spreadsheet like this (data in range B1:B3);
where each row represents a sub-folder and you want to know if you have a file in each of these sub-folders
Then you can use this code. It will write whether there is a file which contains the same name as shown in column B to column C.
Public Sub FindFiles()
Dim myParentFolderLoc As String
Dim curValue As String
Dim myCell As Range
Dim myRange As Range
Dim outputRange As Range
' Change these to your range/Folder Location;
Set myRange = Sheet1.Range("B1:B3")
Set outputRange = Sheet1.Range("B1:C3") ' note the inclusion of the column to which i am writing
myParentFolderLoc = "C:Example Folder"
' Loop through your excel cells
For Each myCell In myRange.Cells
If isFileInFolder(myParentFolderLoc, myCell.Value) Then
myCell.Offset(0, 1).Value = "Files Exists"
Else
myCell.Offset(0, 1).Value = "No Files Exists"
End If
Next myCell
' Export to Txt
ExportRangeToTxt outputRange
End Sub
' Loop through the folder and see if a file contains the string
Private Function isFileInFolder(folderLocation As String, folderName As String) As Boolean
Dim i As Integer
i = 0
file = Dir(folderLocation & folderName & "")
While (file <> "")
i = i + 1
file = Dir
Wend
If i > 0 Then
isFileInFolder = True
Else
isFileInFolder = False
End If
End Function
Private Sub ExportRangeToTxt(myRange As Range)
Dim myFile As String
Dim rng As Range
Dim cellValue As Variant
Dim i As Integer
Dim j As Integer
myFile = Application.DefaultFilePath & "output.txt"
Set rng = myRange
Open myFile For Output As #1
For i = 1 To rng.Rows.Count
For j = 1 To rng.Columns.Count
cellValue = rng.Cells(i, j).Value
If j = rng.Columns.Count Then
Write #1, cellValue
Else
Write #1, cellValue,
End If
Next j
Next i
Close #1
MsgBox "Text Export Complete - Check the file at: " & myFile
End Sub
This will export a file to the default file path of the application - the message box will tell you where this is.
Remember to update the ranges as shown for the example to include all your sub-folders. I could do this automatically but i dont want to make any assumptions having not seen your data.
edited Nov 24 '18 at 23:24
answered Nov 23 '18 at 11:17
James CookeJames Cooke
375210
375210
Thanks! However, the files inside the folders do not have the same name as the folder. Thus: I have a list of values in Excel with identification numbers (e.g. ABCDE1234) and I have a list folders that are named the same. However, some of these folders contain files and some don't. I only need to known which folders contain files or which are empty
– jtsbattle
Nov 23 '18 at 14:06
Ideally, the results could be saved in a .txt file
– jtsbattle
Nov 23 '18 at 14:32
so what is in your excel sheet is a folder - and you need to know what folders have files in them? and they are all subfolders underneath a parent folder?
– James Cooke
Nov 23 '18 at 14:47
Yes that's exactly what I need!
– jtsbattle
Nov 23 '18 at 15:11
go on then.. its friday I will add the .txt thing.
– James Cooke
Nov 23 '18 at 15:12
|
show 3 more comments
Thanks! However, the files inside the folders do not have the same name as the folder. Thus: I have a list of values in Excel with identification numbers (e.g. ABCDE1234) and I have a list folders that are named the same. However, some of these folders contain files and some don't. I only need to known which folders contain files or which are empty
– jtsbattle
Nov 23 '18 at 14:06
Ideally, the results could be saved in a .txt file
– jtsbattle
Nov 23 '18 at 14:32
so what is in your excel sheet is a folder - and you need to know what folders have files in them? and they are all subfolders underneath a parent folder?
– James Cooke
Nov 23 '18 at 14:47
Yes that's exactly what I need!
– jtsbattle
Nov 23 '18 at 15:11
go on then.. its friday I will add the .txt thing.
– James Cooke
Nov 23 '18 at 15:12
Thanks! However, the files inside the folders do not have the same name as the folder. Thus: I have a list of values in Excel with identification numbers (e.g. ABCDE1234) and I have a list folders that are named the same. However, some of these folders contain files and some don't. I only need to known which folders contain files or which are empty
– jtsbattle
Nov 23 '18 at 14:06
Thanks! However, the files inside the folders do not have the same name as the folder. Thus: I have a list of values in Excel with identification numbers (e.g. ABCDE1234) and I have a list folders that are named the same. However, some of these folders contain files and some don't. I only need to known which folders contain files or which are empty
– jtsbattle
Nov 23 '18 at 14:06
Ideally, the results could be saved in a .txt file
– jtsbattle
Nov 23 '18 at 14:32
Ideally, the results could be saved in a .txt file
– jtsbattle
Nov 23 '18 at 14:32
so what is in your excel sheet is a folder - and you need to know what folders have files in them? and they are all subfolders underneath a parent folder?
– James Cooke
Nov 23 '18 at 14:47
so what is in your excel sheet is a folder - and you need to know what folders have files in them? and they are all subfolders underneath a parent folder?
– James Cooke
Nov 23 '18 at 14:47
Yes that's exactly what I need!
– jtsbattle
Nov 23 '18 at 15:11
Yes that's exactly what I need!
– jtsbattle
Nov 23 '18 at 15:11
go on then.. its friday I will add the .txt thing.
– James Cooke
Nov 23 '18 at 15:12
go on then.. its friday I will add the .txt thing.
– James Cooke
Nov 23 '18 at 15:12
|
show 3 more comments
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53443778%2ffind-folders-that-contain-a-file-vba%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
You could use the FileSystemObject . A google search might throw up examples
– Harassed Dad
Nov 23 '18 at 9:37
Welcome to SO. How would I best do this? You could code some loops to check folders and subfolders and find what you are looking for.
– Foxfire And Burns And Burns
Nov 23 '18 at 9:53
Thank you for your replies! I'm relatively new to VBA so where would I start? I found some code on Google that comes close to my solution but I can't seem to make it suit my dataset and folders
– jtsbattle
Nov 23 '18 at 10:19
@jtsbattle So for each identification number in your Excel file, you want to find all subfolders (in a particular folder) which contain the identification number in their name -- and then for each of these found subfolders (which do contain the identification number in their name), you want to do what? Check if each subfolder contains PDF files? Check if each subfolder contains any files?
– chillin
Nov 23 '18 at 11:14
@chillin I have a list of ID numbers in an Excel file and I have a directory containing a lot of folders that have the same numbers as the ID numbers in the Excel file. So for every ID number in the Excel file, there is a folder available as well. However, some of these folders have files and some are empty. For each ID number in Excel, I would like to know which folders are empty (and thus also which are not). I hope this clarifies it!
– jtsbattle
Nov 23 '18 at 14:23