hello - I have been working on how to check and copy (would love to merge or sync) sheets from one workbook to another. The reason is that I have to input data on a PC that is stripped and/or blocked from running macros, then work on the data in a different office that allows macros.
So I have been entering the data on a non-macro enabled workbook, then opening an entirely different WB (when I get the chance on a pc that is allowed to run it) which has a macro to open the orignial. With both open I can use macros to manipulate the data on both sheets.
BUT this has become problematic so I am trying to write a macro to copy the data, including checking and adding new sheets from the non-enabled to the enabled macro PC.
Here is what I got (after several attempts at other ideas)
I would appreciate any help - thanks - Jim A
So I have been entering the data on a non-macro enabled workbook, then opening an entirely different WB (when I get the chance on a pc that is allowed to run it) which has a macro to open the orignial. With both open I can use macros to manipulate the data on both sheets.
BUT this has become problematic so I am trying to write a macro to copy the data, including checking and adding new sheets from the non-enabled to the enabled macro PC.
Here is what I got (after several attempts at other ideas)
Code:
Sub makeCopy_ClosedWorksheet()
' turn off features
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
' constants
Const PATH = "\\network_somewhere\Shared\Education\Teachers\Myers\Excel Folder\"
Const FILE = PATH & "Student List.xlsx"
' variables
Dim thisWb, otherWb As Workbook
Dim thisWs, otherWs, tws, ows As Worksheet
Dim i As Integer: i = 0
Dim C As Integer: C = 0
Dim thisRg, otherRg As Range
' set-up
On Error Resume Next
Set thisWb = Application.ActiveWorkbook
Set otherWb = Workbooks("Student List")
If otherWb Is Nothing Then
Set otherWb = Application.Workbooks.Open(FILE)
End If
On Error GoTo 0 'canceling On Error command from above
For Each ows In otherWb.Worksheets
For Each tws In thisWb.Worksheets
C = C + 1
If tws.Name = ows.Name Then
MsgBox (tws.Name & " - " & ows.Name & ". Looped through " & C & " times.")
Set thisRg = tws.Range("A1:E100")
Set otherRg = ows.Range("A1:E100")
otherRg.Copy (thisRg) 'copy wrksheet contents
Else
tws.Copy after:=Workbooks("TEST4i.xlsm").Sheets(C)
MsgBox (tws.Name & " sheet made.")
End If
Next tws
Next ows
' reset variable
i = 0: C = 0
' save this workbook
thisWb.Save
' clean up
Set otherWs = Nothing
otherWb.Close
Set otherWb = Nothing
Set thisWb = Nothing
Set thisWs = Nothing
' restore features
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
Application.Calculate
End Sub
I would appreciate any help - thanks - Jim A
Last edited: