Using Mac Excel 2011 btw which is why you see a ":" instead of a "/".
I'm trying to take the data from a batch of files in a subfolder called "Old" which is located in the directory below my template file. Copy and paste the data from those files into my active workbook which is a new template. Then save that file in another subfolder called new, currently just trying to save the file as "Test".
Noting happens when I run my code and neither value seems to populate, not exactly sure why :/
Any help would be much appreciated.
I'm trying to take the data from a batch of files in a subfolder called "Old" which is located in the directory below my template file. Copy and paste the data from those files into my active workbook which is a new template. Then save that file in another subfolder called new, currently just trying to save the file as "Test".
Noting happens when I run my code and neither value seems to populate, not exactly sure why :/
Any help would be much appreciated.
Rich (BB code):
Sub NewTemplate_Conversion()
Dim MyPath As String, FilesInPath As String
Dim MyFiles() As String, Fnum As Long
Dim Filename As String
Dim mybook As Workbook
Dim CalcMode As Long
Dim sh As Worksheet
Dim ErrorYes As Boolean
'Fill in the path\folder where the files are
MyPath = Application.ActiveWorkbook.Path & ":Old:"
'If there are no Excel files in the folder exit the sub
FilesInPath = Dir(MyPath)
If FilesInPath = "" Then
MsgBox "No files found"
Exit Sub
End If
'Fill the array(myFiles)with the list of Excel files in the folder
Fnum = 0
Do While FilesInPath <> ""
Fnum = Fnum + 1
ReDim Preserve MyFiles(1 To Fnum)
MyFiles(Fnum) = FilesInPath
FilesInPath = Dir()
Loop
With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
.EnableEvents = False
End With
'Loop through all files in the array(myFiles)
If Fnum > 0 Then
For Fnum = LBound(MyFiles) To UBound(MyFiles)
Set mybook = Nothing
On Error Resume Next
Set mybook = Workbooks.Open(MyPath & MyFiles(Fnum))
If Not mybook Is Nothing Then
With Application.ActiveWorkbook.Worksheets("Project")
.Range("A1").Value = mybook.Worksheets("1 Estimator v1.25 thru 12-06new").Range("B3").Value
.Range("A2").Value = "success"
Application.Calculate
Filename = "Test"
Application.ActiveWorkbook.SaveAs Application.ActiveWorkbook.Path & ":New:" & Filename, FileFormat:=53
End With
mybook.Close savechanges:=False
End If
Next Fnum
End If
With Application
.ScreenUpdating = True
.EnableEvents = True
.Calculation = CalcMode
End With
End Sub