I have 2 Workbooks open (one is called "Machine_Data.xls" and the other is "Corrections_Data.xlsx") the goal is to pass variable values from one book to the other and it is working, but in addition to the cells I would like to run a macro present in the first book in the second book, can someone help me?
Code for pass values:
Macro:
The macro would have to be executed on the cells scrawled in blue
Code for pass values:
VBA Code:
Private Sub Write_Miter()
Workbooks("Corrections_Data.xlsx").Sheets("Miter_Registers").Cells(k_miter, 14).Value = Y1_Axis_Orig_D
Workbooks("Corrections_Data.xlsx").Sheets("Miter_Registers").Cells(k_miter, 15).Value = Y2_Axis_Orig_D
Workbooks("Corrections_Data.xlsx").Sheets("Miter_Registers").Cells(k_miter, 16).Value = Z_100_Orig_D
Workbooks("Corrections_Data.xlsx").Sheets("Miter_Registers").Cells(k_miter, 17).Value = Z_250_Orig_D
Workbooks("Corrections_Data.xlsx").Sheets("Miter_Registers").Cells(k_miter, 18).Value = Z_400_Orig_D
Workbooks("Corrections_Data.xlsx").Sheets("Miter_Registers").Cells(k_miter, 19).Value = Z_550_Orig_D
Workbooks("Corrections_Data.xlsx").Sheets("Miter_Registers").Cells(k_miter, 20).Select
Miter_2.ColorCells_Miter_2
Workbooks("Corrections_Data.xlsx").Sheets("Miter_Registers").Cells(k_miter, 21).Value = X1_Axis_Orig
Workbooks("Corrections_Data.xlsx").Sheets("Miter_Registers").Cells(k_miter, 22).Value = X2_Axis_Orig
Workbooks("Corrections_Data.xlsx").Sheets("Miter_Registers").Cells(k_miter, 23).Value = Z_100_Final
Workbooks("Corrections_Data.xlsx").Sheets("Miter_Registers").Cells(k_miter, 24).Value = Z_250_Final
Workbooks("Corrections_Data.xlsx").Sheets("Miter_Registers").Cells(k_miter, 25).Value = Z_400_Final
Workbooks("Corrections_Data.xlsx").Sheets("Miter_Registers").Cells(k_miter, 26).Value = Z_550_Final
End Sub
Macro:
Code:
Public Sub ColorCells_Miter_2()
If ActiveCell.Column = 20 Then
If Z_550_Orig_D <= 0 And Y2_Axis_Orig_D <= 0 Then
If Abs(Z_550_Orig_D * 1) + Abs(Y2_Axis_Orig_D * 1) < 30 Then
ActiveCell.Interior.ColorIndex = 4
ActiveCell.Font.Color = vbBlack
ActiveCell.Value = "Não Precisa de Correção"
ElseIf Abs(Z_550_Orig_D * 1) + Abs(Y2_Axis_Orig_D * 1) >= 30 Then
ActiveCell.Interior.ColorIndex = 3
ActiveCell.Value = "Correção Necessária"
End If
ElseIf Z_550_Orig_D > 0 And Y2_Axis_Orig_D <= 0 Then
If Abs(Z_550_Orig_D + (Y2_Axis_Orig_D * 1)) < 30 Then
ActiveCell.Interior.ColorIndex = 4
ActiveCell.Font.Color = vbBlack
ActiveCell.Value = "Não Precisa de Correção"
ElseIf Abs(Z_550_Orig_D + (Y2_Axis_Orig_D * 1)) >= 30 Then
ActiveCell.Interior.ColorIndex = 3
ActiveCell.Value = "Correção Necessária"
End If
ElseIf Z_550_Orig_D < 0 And Y2_Axis_Orig_D >= 0 Then
If Abs((Z_550_Orig_D * 1) + Y2_Axis_Orig_D) < 30 Then
ActiveCell.Interior.ColorIndex = 4
ActiveCell.Font.Color = vbBlack
ActiveCell.Value = "Não Precisa de Correção"
ElseIf Abs((Z_550_Orig_D * 1) + Y2_Axis_Orig_D) >= 30 Then
ActiveCell.Interior.ColorIndex = 3
ActiveCell.Value = "Correção Necessária"
End If
ElseIf Z_550_Orig_D >= 0 And Y2_Axis_Orig_D >= 0 Then
If Y2_Axis_Orig_D + Z_550_Orig_D < 30 Then
ActiveCell.Interior.ColorIndex = 4
ActiveCell.Font.Color = vbBlack
ActiveCell.Value = "Não Precisa de Correção"
ElseIf Y2_Axis_Orig_D + Z_550_Orig_D >= 30 Then
ActiveCell.Interior.ColorIndex = 3
ActiveCell.Value = "Correção Necessária"
End If
End If
End If
End Sub
The macro would have to be executed on the cells scrawled in blue