I have some code that imports .bas files and i need it to run though 2 named ranges. The first (MacroName) would be a list of file names (e.g exam.bas, print.bas...) and the second (ImportDate) will be the date that the file was imported.
The code below loops though the folder that contains .bas files. It then checks the date modified of the file against the ImportDate named range. But I can't think of a way to loop the named ranges
For Each objFile In objFSO.GetFolder(szImportPath).Files
If objFile.Name Like "*Import*" Then GoTo skipImport ' Skips the Import Module
If (objFSO.GetExtensionName(objFile.Name) = "cls") Or _
(objFSO.GetExtensionName(objFile.Name) = "frm") Or _
(objFSO.GetExtensionName(objFile.Name) = "bas") And _
objFile.DateLastModified > Range("ImportDate") Then
Dim CurrentModuleName
CurrentModuleName = Left(objFile.Name, (InStrRev(objFile.Name, ".", -1, vbTextCompare) - 1))
'^ Gets the file name of the module being imported and removes the extension
Dim VBProj As VBIDE.VBProject
Dim VBComp As VBIDE.VBComponent
Set VBProj = ActiveWorkbook.VBProject
Set VBComp = VBProj.VBComponents(CurrentModuleName)
VBProj.VBComponents.Remove VBComp
'^ Removes the module that is to be replaced
Range("MacroName") = objFile.Name
Range("ImportDate") = Format(Date, "dd/mm/yyyy") & " " & Format(Time, "hh.nn.ss")
'^ Keep time as without, it will import the same module throughout the day when opened.
cmpComponents.Import objFile.path
End If
skipImport:
Next objFile
I am hoping that it reads the name of the file, checks the date and then if the date modified of the imported file is greater, deletes the current and replaces.