VBA Batch Transfer Data of Old File Template to New File Template

DWhit217

New Member
Joined
Mar 29, 2012
Messages
21
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.

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
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Quick update: The code is skipping over ".XLS" files but seems to open ".XLSM" files. Neither is saving a new file called "Test" in the "New" subfolder though.
 
Upvote 0

Forum statistics

Threads
1,215,460
Messages
6,124,949
Members
449,198
Latest member
MhammadishaqKhan

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top