dallas2024
New Member
- Joined
- Oct 25, 2024
- Messages
- 14
- Office Version
- 365
- Platform
- Windows
VBA Code:
Sub WO_SaveUpdate()
Dim WORow As Long, WOCol As Long
Dim AssignedTo As String, SharedFolder As String, FileName As String, FilePath As String
ActiveWorkbook.Save
Application.ScreenUpdating = False
With Sheet1
If .Range("D4").Value = Empty Or .Range("H4").Value = Empty Or .Range("D10").Value = Empty Or .Range("C15").Value = Empty Then
MsgBox "Please Complete Yellow Boxes"
Exit Sub
End If
End With
With Sheet3
If .Range("C4").Value = Empty Then
MsgBox "Please add in a shared folder location"
Exit Sub
End If
End With
With Sheet2
If Worksheets("WO Data").Range("B11").Value = True Then 'new WOrk order
WORow = .Range("C99999").End(xlUp).Row + 1 'First Avail. Row
Else ' Existing Work Order
End If
End With
With Sheet1
For WOCol = 3 To 11
Sheet2.Cells(WORow, WOCol).Value = .Range(.Cells(30, WOCol).Value).Value 'Place values in WO Row
Sheet4.Range(.Cells(29, WOCol).Value).Value = .Range(.Cells(30, WOCol).Value).Value 'Place Values in WO Template
Next WOCol
Sheet2.Range("B11").Value = False 'Set new WO to false
Sheet2.Range("B12").Value = WORow
'Create/Update Work Order in Shared folder if status is Open
If .Range("D8").Value = "Open" Then
AssignedTo = .Range("H4").Value 'Assigned To
SharedFolder = Sheet3.Range("C4").Value 'Shared Folder location
FileName = "Work Order_" & .Range("D6").Value 'File Name Work Order & #
If Dir(SharedFolder & "\" & AssignedTo, vbDirectory) = "" Then MkDir (SharedFolder & "\" & AssignedTo) 'Create Folder if it does not exist
FilePath = SharedFolder & "\" & AssignedTo & "\" & FileName & ".xlsx"
On Error Resume Next
Kill (FilePath)
On Error GoTo 0
Sheet4.Range("A1:B26").Copy
Workbooks.Add
ActiveWorkbook.Sheets(1).Range("A1").PasteSpecial xlPasteAll
ActiveWorkbook.Sheets(1).Range("A1").PasteSpecial xlPasteColumnWidths
ActiveWorkbook.SaveAs FilePath
ActiveWorkbook.Close False
Sheet2.Range("G" & WORow).Value = Now 'Update Assigned On to Current date & Time
Application.ScreenUpdating = True
ActiveWorkbook.Save
End If
End With
End Sub