Hello Everyone . I am looking for a way to copy a worksheet to into specific workbooks in a certain folder.
The workbooks currently do not have this worksheet in them so I would just like to copy the worksheet from the template
into the files on the list. I have a list of files in column A that include the path of each file (the ones without the worksheet).
The open workbook has a worksheet named "Census". The Census worksheet just has headings in row 1.
I would like just open each file on the list and insert a new worksheet named Census.
The template file is Excel 365 but the receiving files are excel 97-2000 so I can't just do a copy/move because I will get an
incompatability error. So my thought is I could use something similar to what I was using to copy and paste data from a file in column A
to a recediving file listed in column B but I am just not sure how to. Any help would be greatly appreciated.
What I have been working with is listed below.
Receiving File (Column A) (In Column B is currently the file the data listed in Column A below would bo to)
S:\Automated Aggregate Detail\Aggregate Workspace\THE PINE SCHOOL, INC.76450080 Mthly Agg 1010 3-1-2022 14786.xls
S:\Automated Aggregate Detail\Aggregate Workspace\HOMESTEAD FINANCIAL MORTGAGE76415401 Mthly Agg 1010 3-1-2022 14782.xls
S:\Automated Aggregate Detail\Aggregate Workspace\E-Z BEL CONSTRUCTION, LLC76415516 Mthly Agg 0710 7-1-2022 14895.xls
Sub Post_10Months()
Range("R1").Value = "Process Running"
Call ShowStart
Application.Wait (VBA.Now + VBA.TimeValue("0:00:3"))
'
Application.ScreenUpdating = False
Sheets("10MONTHS").Select
'
Dim columnX As Range, cell As Range
Set columnX = Range("A2:A1500")
Dim path1, path2 As String
Dim FileOpen As String
Dim ifilenum As Long
For Each cell In columnX
ChDir "S:\ReportingDepartment\ReportingAnalyst\Projects\REX\Original Report Data"
'copies current cell value into path1
path1 = cell.Value
If Dir(path1) = "" Then
Sheets("Dashboard").Select
Range("A2").Select
Do
If IsEmpty(ActiveCell) = False Then
ActiveCell.Offset(1, 0).Select
End If
Loop Until IsEmpty(ActiveCell) = True
ActiveCell = path1 & " - NOT FOUND"
GoTo NoReceivingFile
End If
Workbooks.Open Filename:=path1
Range("A2:M11").Select
Selection.Copy
Application.DisplayAlerts = False
ActiveWindow.Close
Application.DisplayAlerts = True
ChDir "S:\ReportingDepartment\ReportingAnalyst\Projects\REX\Reports To Be Sent"
'copies the vaule of the offset to thr right cell into path2
path2 = cell.Offset(0, 1).Value
On Error Resume Next
ifilenum = FreeFile()
Open path2 For Input Lock Read As #ifilenum
Close #ifilenum
Application.CutCopyMode = False
If Err.Number <> 70 Then 'file is close
Workbooks.Open Filename:=path2
Sheets("Detail").Select
Range("A5:M14").Select
Application.DisplayAlerts = False
ActiveSheet.PasteSpecial Format:="Unicode Text", Link:=False, _
DisplayAsIcon:=False, NoHTMLFormatting:=True
Application.DisplayAlerts = True
Range("B5:B17").Select
Selection.NumberFormat = "0"
Columns("B:B").EntireColumn.AutoFit
Range("A3").Select
Sheets("Summary").Select
ActiveWorkbook.Save
ActiveWindow.Close
Else
Sheets("Dashboard").Select
Range("A2").Select
'Range("d8").Value = path2
Do
If IsEmpty(ActiveCell) = False Then
ActiveCell.Offset(1, 0).Select
End If
Loop Until IsEmpty(ActiveCell) = True
ActiveCell.Value = path2
'ActiveCell.PasteSpecial Paste:=xlPasteValues
End If
NoReceivingFile:
Next cell
'
'
Exit Sub
Application.DisplayAlerts = False
Range("E3").Value = "Process Complete"
Do
If IsEmpty(ActiveCell) = False Then
ActiveCell.Offset(1, 0).Select
End If
Loop Until IsEmpty(ActiveCell) = True
Range("d8").Value = path2
ActiveCell.PasteSpecial Paste:=xlPasteValues
'
'
Resume Next ' go back to the line following the error
Call add_posted10
Call ShowEnd
End Sub
The workbooks currently do not have this worksheet in them so I would just like to copy the worksheet from the template
into the files on the list. I have a list of files in column A that include the path of each file (the ones without the worksheet).
The open workbook has a worksheet named "Census". The Census worksheet just has headings in row 1.
I would like just open each file on the list and insert a new worksheet named Census.
The template file is Excel 365 but the receiving files are excel 97-2000 so I can't just do a copy/move because I will get an
incompatability error. So my thought is I could use something similar to what I was using to copy and paste data from a file in column A
to a recediving file listed in column B but I am just not sure how to. Any help would be greatly appreciated.
What I have been working with is listed below.
Receiving File (Column A) (In Column B is currently the file the data listed in Column A below would bo to)
S:\Automated Aggregate Detail\Aggregate Workspace\THE PINE SCHOOL, INC.76450080 Mthly Agg 1010 3-1-2022 14786.xls
S:\Automated Aggregate Detail\Aggregate Workspace\HOMESTEAD FINANCIAL MORTGAGE76415401 Mthly Agg 1010 3-1-2022 14782.xls
S:\Automated Aggregate Detail\Aggregate Workspace\E-Z BEL CONSTRUCTION, LLC76415516 Mthly Agg 0710 7-1-2022 14895.xls
Sub Post_10Months()
Range("R1").Value = "Process Running"
Call ShowStart
Application.Wait (VBA.Now + VBA.TimeValue("0:00:3"))
'
Application.ScreenUpdating = False
Sheets("10MONTHS").Select
'
Dim columnX As Range, cell As Range
Set columnX = Range("A2:A1500")
Dim path1, path2 As String
Dim FileOpen As String
Dim ifilenum As Long
For Each cell In columnX
ChDir "S:\ReportingDepartment\ReportingAnalyst\Projects\REX\Original Report Data"
'copies current cell value into path1
path1 = cell.Value
If Dir(path1) = "" Then
Sheets("Dashboard").Select
Range("A2").Select
Do
If IsEmpty(ActiveCell) = False Then
ActiveCell.Offset(1, 0).Select
End If
Loop Until IsEmpty(ActiveCell) = True
ActiveCell = path1 & " - NOT FOUND"
GoTo NoReceivingFile
End If
Workbooks.Open Filename:=path1
Range("A2:M11").Select
Selection.Copy
Application.DisplayAlerts = False
ActiveWindow.Close
Application.DisplayAlerts = True
ChDir "S:\ReportingDepartment\ReportingAnalyst\Projects\REX\Reports To Be Sent"
'copies the vaule of the offset to thr right cell into path2
path2 = cell.Offset(0, 1).Value
On Error Resume Next
ifilenum = FreeFile()
Open path2 For Input Lock Read As #ifilenum
Close #ifilenum
Application.CutCopyMode = False
If Err.Number <> 70 Then 'file is close
Workbooks.Open Filename:=path2
Sheets("Detail").Select
Range("A5:M14").Select
Application.DisplayAlerts = False
ActiveSheet.PasteSpecial Format:="Unicode Text", Link:=False, _
DisplayAsIcon:=False, NoHTMLFormatting:=True
Application.DisplayAlerts = True
Range("B5:B17").Select
Selection.NumberFormat = "0"
Columns("B:B").EntireColumn.AutoFit
Range("A3").Select
Sheets("Summary").Select
ActiveWorkbook.Save
ActiveWindow.Close
Else
Sheets("Dashboard").Select
Range("A2").Select
'Range("d8").Value = path2
Do
If IsEmpty(ActiveCell) = False Then
ActiveCell.Offset(1, 0).Select
End If
Loop Until IsEmpty(ActiveCell) = True
ActiveCell.Value = path2
'ActiveCell.PasteSpecial Paste:=xlPasteValues
End If
NoReceivingFile:
Next cell
'
'
Exit Sub
Application.DisplayAlerts = False
Range("E3").Value = "Process Complete"
Do
If IsEmpty(ActiveCell) = False Then
ActiveCell.Offset(1, 0).Select
End If
Loop Until IsEmpty(ActiveCell) = True
Range("d8").Value = path2
ActiveCell.PasteSpecial Paste:=xlPasteValues
'
'
Resume Next ' go back to the line following the error
Call add_posted10
Call ShowEnd
End Sub