Good Morning All,
Still a little new to the excel vba programming but was hoping that someone could assist me in a macro I wish to create. I have a folder containing n number of data files all of the same format and wish to create a macro that will loop through all of the files in the folder and apply the macro listed below.
I have set up the macro below to run through one data file that has been selected by the user and now wish to apply it to all files in said folder. I know there is a loop option but can anyone explain to me how to do this?
Thanks so much,
Mel
Sub Import_PCH_File()
'
' Import_PCH_File Macro
' Importing PCH File to run Stiffness_Macro
'
Dim Input_File As Variant
Dim Input_File_Name As String
Input_File = Application.GetOpenFilename(Title:="Choose your file", _
FileFilter:="All Files (*.*), *.*")
Input_File_Name = CStr(Input_File)
If Right(Input_File_Name, 1) <> "\" Then Input_File_Name = Input_File_Name & "\"
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;" & Input_File, _
Destination:=Range("$A$1"))
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlFixedWidth
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1)
.TextFileFixedColumnWidths = Array(16, 2, 20, 16, 20)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
Sheets("Limits").Select
Calculate
Sheets("Extracted_Data").Select
Calculate
Sheets("Stiffness_Calculator").Select
Calculate
Sheets("Stiffness_Plots").Select
Calculate
Sheets("LL_Results").Select
Calculate
Sheets("UL_Results").Select
Calculate
ActiveWorkbook.SaveAs Filename:=Left(Input_File_Name, InStrRev(Input_File_Name, ".")) & "xlsm", FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
End Sub
Bookmarks