Вы находитесь на странице: 1из 18

New Contract (Create a new contract and ACW Master Agreement workspace only)

Sub CheckBeforeMail10()

If Worksheets("NEW CONTRACT - MASTER ONLY").Range("K71") = "" Then MsgBox ("Complete Workgroup Field") Range("K71").Select Exit Sub Else End If

If Worksheets("Compliance Worksheet").Range("P5") = 1 And Worksheets("Compliance Worksheet").Range("P13") = 1 And Worksheets("Compliance Worksheet").Range("P14") = 1 And Worksheets("Compliance Worksheet").Range("P24") = 0 And Worksheets("Financial Worksheet").Range("I10") = 0 And Worksheets("HES_IRM_Capability").Range("R7") = 2 And Worksheets("HES_IRM_Capability").Range("R10") = 1 And Worksheets("HES_IRM_Capability").Range("R11") = 1 And Worksheets("HES_IRM_Capability").Range("R16") = 1 And Worksheets("HES_IRM_Capability").Range("R20") = 1 Then MsgBox ("Please complete the Compliance, Financial and HES, IRM, Capability Worksheets") Worksheets("Compliance Worksheet").Activate Range("C5").Select Exit Sub Else End If

If Worksheets("Compliance Worksheet").Range("P5") = 1 Then MsgBox ("Please answer Question I in Compliance Worksheet") Worksheets("Compliance Worksheet").Activate

Range("C5").Select Exit Sub Else End If

If Worksheets("Compliance Worksheet").Range("P13") = 1 Then MsgBox ("Please answer Question II in Compliance Worksheet") Worksheets("Compliance Worksheet").Activate Range("C13").Select Exit Sub Else End If

If Worksheets("Compliance Worksheet").Range("P14") = 1 Then MsgBox ("Please answer Question III in Compliance Worksheet") Worksheets("Compliance Worksheet").Activate Range("C14").Select Exit Sub Else End If

If Worksheets("Compliance Worksheet").Range("P24") = 0 Then MsgBox ("Please complete the Compliance Worksheet Matrix") Worksheets("Compliance Worksheet").Activate Range("J24").Select

Exit Sub Else End If

If Worksheets("Financial Worksheet").Range("I10") = 0 Then MsgBox ("Please complete the Financial Worksheet Matrix") Worksheets("Financial Worksheet").Activate Range("E12").Select Exit Sub Else End If

If Worksheets("HES_IRM_Capability").Range("R7") = 2 Then MsgBox ("Please answer all HES questions") Worksheets("HES_IRM_Capability").Activate Range("D5").Select Exit Sub Else End If

If Worksheets("HES_IRM_Capability").Range("R7") = 3 And Worksheets("HES_IRM_Capability").Range("R8") = 1 Then MsgBox ("Please select Risk Level") Worksheets("HES_IRM_Capability").Activate Range("D7").Select Exit Sub

Else End If

If Worksheets("HES_IRM_Capability").Range("R10") = 1 Then MsgBox ("Please answer all HES questions") Worksheets("HES_IRM_Capability").Activate Range("D9").Select Exit Sub Else End If

If Worksheets("HES_IRM_Capability").Range("R11") = 1 Then MsgBox ("Please answer all HES questions") Worksheets("HES_IRM_Capability").Activate Range("D11").Select Exit Sub Else End If

If Worksheets("HES_IRM_Capability").Range("R16") = 1 Then MsgBox ("Please answer the Information Risk Management (IRM) question") Worksheets("HES_IRM_Capability").Activate Range("D16").Select Exit Sub

Else End If

If Worksheets("HES_IRM_Capability").Range("R20") = 1 Then MsgBox ("Please answer the question on Capability") Worksheets("HES_IRM_Capability").Activate Range("D21").Select Exit Sub Else End If

'Working in 97-2010 Dim FileExtStr As String Dim FileFormatNum As Long Dim Sourcewb As Workbook Dim Destwb As Workbook Dim TempFilePath As String Dim TempFileName As String Dim sh As Worksheet Dim TheActiveWindow As Window Dim TempWindow As Window Dim I As Long

With Application .ScreenUpdating = False

.EnableEvents = False End With

Set Sourcewb = ActiveWorkbook

'Copy the sheets to a new workbook 'We add a temporary Window to avoid the Copy problem 'if there is a List or Table in one of the sheets and 'if the sheets are grouped With Sourcewb Set TheActiveWindow = ActiveWindow Set TempWindow = .NewWindow .Sheets(Array("NEW CONTRACT - MASTER ONLY", "Compliance Worksheet", "Financial Worksheet", "HES_IRM_Capability", "Fields")).Copy End With

'Close temporary Window TempWindow.Close

Set Destwb = ActiveWorkbook

'Determine the Excel version and file extension/format With Destwb If Val(Application.Version) < 12 Then 'You use Excel 97-2003 FileExtStr = ".xls": FileFormatNum = -4143

Else 'You use Excel 2007-2010, we exit the sub when your answer is 'NO in the security dialog that you only see when you copy 'an sheet from a xlsm file with macro's disabled. If Sourcewb.Name = .Name Then With Application .ScreenUpdating = True .EnableEvents = True End With MsgBox "Your answer is NO in the security dialog" Exit Sub Else Select Case Sourcewb.FileFormat Case 51: FileExtStr = ".xlsx": FileFormatNum = 51 Case 52: If .HasVBProject Then FileExtStr = ".xlsm": FileFormatNum = 52 Else FileExtStr = ".xlsx": FileFormatNum = 51 End If Case 56: FileExtStr = ".xls": FileFormatNum = 56 Case Else: FileExtStr = ".xlsb": FileFormatNum = 50 End Select End If End If

End With

' 'Change all cells in the worksheets to values if you want ' For Each sh In Destwb.Worksheets ' ' ' ' ' ' ' ' sh.Select With sh.UsedRange .Cells.Copy .Cells.PasteSpecial xlPasteValues .Cells(1).Select End With Application.CutCopyMode = False Destwb.Worksheets(1).Select

' Next sh

'Save the new workbook/Mail it/Delete it TempFilePath = Environ$("temp") & "\" TempFileName = "Work Request Form " & Sourcewb.Name _

With Destwb .SaveAs TempFilePath & TempFileName & FileExtStr, _ FileFormat:=FileFormatNum On Error Resume Next For I = 1 To 3 .SendMail "jaybee.a.cana@chevron.com ", _ "WRF" & " " & "-" & " " & Range("C8") & " " & "-" & " " & Range("K71") & " " & "-" & " " & Range("K73") & " " & "(" & Range("H15") & ")"

If Err.Number = 0 Then Exit For Next I On Error GoTo 0 .Close SaveChanges:=False End With

Kill TempFilePath & TempFileName & FileExtStr

With Application .ScreenUpdating = True .EnableEvents = True End With End Sub _____________________________________________________________________________________

New Contract (Create a new contract and ACW Master & Sub Agreement workspaces)
Sub CheckBeforeMail11()

If Worksheets("NEW CONTRACT - MASTERSUB").Range("K78") = "" Then MsgBox ("Complete Workgroup Field") Range("K78").Select Exit Sub Else End If

If Worksheets("Compliance Worksheet").Range("P5") = 1 And Worksheets("Compliance Worksheet").Range("P13") = 1 And Worksheets("Compliance Worksheet").Range("P14") = 1 And

Worksheets("Compliance Worksheet").Range("P24") = 0 And Worksheets("Financial Worksheet").Range("I10") = 0 And Worksheets("HES_IRM_Capability").Range("R7") = 2 And Worksheets("HES_IRM_Capability").Range("R10") = 1 And Worksheets("HES_IRM_Capability").Range("R11") = 1 And Worksheets("HES_IRM_Capability").Range("R16") = 1 And Worksheets("HES_IRM_Capability").Range("R20") = 1 Then MsgBox ("Please complete the Compliance, Financial and HES, IRM, Capability Worksheets") Worksheets("Compliance Worksheet").Activate Range("C5").Select Exit Sub Else End If

If Worksheets("Compliance Worksheet").Range("P5") = 1 Then MsgBox ("Please answer Question I in Compliance Worksheet") Worksheets("Compliance Worksheet").Activate Range("C5").Select Exit Sub Else End If

If Worksheets("Compliance Worksheet").Range("P13") = 1 Then MsgBox ("Please answer Question II in Compliance Worksheet") Worksheets("Compliance Worksheet").Activate Range("C13").Select Exit Sub Else

End If

If Worksheets("Compliance Worksheet").Range("P14") = 1 Then MsgBox ("Please answer Question III in Compliance Worksheet") Worksheets("Compliance Worksheet").Activate Range("C14").Select Exit Sub Else End If

If Worksheets("Compliance Worksheet").Range("P24") = 0 Then MsgBox ("Please complete the Compliance Worksheet Matrix") Worksheets("Compliance Worksheet").Activate Range("J24").Select Exit Sub Else End If

If Worksheets("Financial Worksheet").Range("I10") = 0 Then MsgBox ("Please complete the Financial Worksheet Matrix") Worksheets("Financial Worksheet").Activate Range("E12").Select Exit Sub Else End If

If Worksheets("HES_IRM_Capability").Range("R7") = 2 Then MsgBox ("Please answer all HES questions") Worksheets("HES_IRM_Capability").Activate Range("D5").Select Exit Sub Else End If

If Worksheets("HES_IRM_Capability").Range("R7") = 3 And Worksheets("HES_IRM_Capability").Range("R8") = 1 Then MsgBox ("Please select Risk Level") Worksheets("HES_IRM_Capability").Activate Range("D7").Select Exit Sub Else End If

If Worksheets("HES_IRM_Capability").Range("R10") = 1 Then MsgBox ("Please answer all HES questions") Worksheets("HES_IRM_Capability").Activate Range("D9").Select Exit Sub Else End If

If Worksheets("HES_IRM_Capability").Range("R11") = 1 Then MsgBox ("Please answer all HES questions") Worksheets("HES_IRM_Capability").Activate Range("D11").Select Exit Sub Else End If

If Worksheets("HES_IRM_Capability").Range("R16") = 1 Then MsgBox ("Please answer the Information Risk Management (IRM) question") Worksheets("HES_IRM_Capability").Activate Range("D16").Select Exit Sub Else End If

If Worksheets("HES_IRM_Capability").Range("R20") = 1 Then MsgBox ("Please answer the question on Capability") Worksheets("HES_IRM_Capability").Activate Range("D21").Select Exit Sub Else End If

'Working in 97-2010 Dim FileExtStr As String Dim FileFormatNum As Long Dim Sourcewb As Workbook Dim Destwb As Workbook Dim TempFilePath As String Dim TempFileName As String Dim sh As Worksheet Dim TheActiveWindow As Window Dim TempWindow As Window Dim I As Long

With Application .ScreenUpdating = False .EnableEvents = False End With

Set Sourcewb = ActiveWorkbook

'Copy the sheets to a new workbook 'We add a temporary Window to avoid the Copy problem 'if there is a List or Table in one of the sheets and 'if the sheets are grouped With Sourcewb Set TheActiveWindow = ActiveWindow

Set TempWindow = .NewWindow .Sheets(Array("NEW CONTRACT - MASTERSUB", "Compliance Worksheet", "Financial Worksheet", "HES_IRM_Capability", "Fields")).Copy End With

'Close temporary Window TempWindow.Close

Set Destwb = ActiveWorkbook

'Determine the Excel version and file extension/format With Destwb If Val(Application.Version) < 12 Then 'You use Excel 97-2003 FileExtStr = ".xls": FileFormatNum = -4143 Else 'You use Excel 2007-2010, we exit the sub when your answer is 'NO in the security dialog that you only see when you copy 'an sheet from a xlsm file with macro's disabled. If Sourcewb.Name = .Name Then With Application .ScreenUpdating = True .EnableEvents = True End With MsgBox "Your answer is NO in the security dialog" Exit Sub

Else Select Case Sourcewb.FileFormat Case 51: FileExtStr = ".xlsx": FileFormatNum = 51 Case 52: If .HasVBProject Then FileExtStr = ".xlsm": FileFormatNum = 52 Else FileExtStr = ".xlsx": FileFormatNum = 51 End If Case 56: FileExtStr = ".xls": FileFormatNum = 56 Case Else: FileExtStr = ".xlsb": FileFormatNum = 50 End Select End If End If End With

' 'Change all cells in the worksheets to values if you want ' For Each sh In Destwb.Worksheets ' ' ' ' ' ' ' sh.Select With sh.UsedRange .Cells.Copy .Cells.PasteSpecial xlPasteValues .Cells(1).Select End With Application.CutCopyMode = False

'

Destwb.Worksheets(1).Select

' Next sh

'Save the new workbook/Mail it/Delete it TempFilePath = Environ$("temp") & "\" TempFileName = "Work Request Form " & Sourcewb.Name _

With Destwb .SaveAs TempFilePath & TempFileName & FileExtStr, _ FileFormat:=FileFormatNum On Error Resume Next For I = 1 To 3 .SendMail "jaybee.a.cana@chevron.com ", _ "WRF" & " " & "-" & " " & Range("C8") & " " & "-" & " " & Range("K78") & " " & "-" & " " & Range("K80") & " " & "(" & Range("H15") & ")" If Err.Number = 0 Then Exit For Next I On Error GoTo 0 .Close SaveChanges:=False End With

Kill TempFilePath & TempFileName & FileExtStr

With Application .ScreenUpdating = True .EnableEvents = True

End With End Sub _____________________________________________________________________________________

Вам также может понравиться