Hello!
First, thank you for reading. I've used VBA tons of times in the past to make my life easier, but now I'm actually studying Programming to get a degree in it so I know what it is that I'm doing instead of recording macros or modifying code. The issue is that at this point in my studies, I familiar with Python, so I am having trouble with the VBA language.
I was trying to create a Macro in which the user would input a string, then the macro would search 3 separate folders (A, B & C) and their subfolders for file names that would contain the string (be partial file name). The macro would then open said files.
All my attempts have failed. I've looked around the past few days, but haven't had any luck.
Here is the VBA code for the first folder (Folder A) that I've most recently tried (and failed). And because I'm been programmed to do so (ha, ha) I put the psuedocode I wrote for my macro underneath. Please forgive any rookie mistakes.
Thank you for any help.
[code] Sub allFolders()
Dim tlcNumber As String
Dim folderA As String
Dim fileA As String
tlcNumber = InputBox("Enter TLC in either X-XX, XX-XX or XX-XXX format()")
folderA = "\\file path"
fileA = Dir(folderA & "\*.xlsm")
Do Until fileA = ""
Workbook.Open Filename:=tlcNumber & "" & fileA
fileA = Dir
Loop
End Sub [code]
All Folders Psuedocode
//Declare variables
Declare String tlcNumber
//global constants as the location will never change
Set folderA = network location
Set folderB = network location
Set folderC = network location
// Call Modules
Call Main()
Call findTLC(tlcNumber)
Call openFiles(tlcNumber)
Module findTLC (String tlcNumber)
//To input the TLC for the line you are looking for
Display “Enter the TLC to identify the line in XX-XX, X-XXX or XX-XXX format.”
Input tlcNumber
Module openFiles(tlcNumber)
// Search the TLC number in the A folder and subfolders then open file
Find(tlcNumber folderA)
For files in folderA
If tlcNumber name in file Then
Open(file)
Else
Display “No file found”
// Search the TLC number in the B folder and subfolders then open file
Find(tlcNumber, folderB)
For files in folderB
If tlcNumber name in file Then
Open(file)
Else
Display “No file found”
// Search the TLC number in the C folder and subfolders then open file
Find(tlcNumber, folderC)
For files in folderC
If tlcNumber name in file Then
Open(file)
Else
Display “No file found”
Call Main():
Bookmarks