Is there a macro I can put on a command button, to move the current sheet to a different closed workbook?

  Question:

I have 2 workbooks for the department. "Workorders" & "Completed Workorders" "Workorders" is a shared book that other departments put in Task request. The guys in the department, fill them out when they have completed the task. Each Sheet is renamed with the task number ID, so the sheet is never the same name. The "Workorders" book needs to be the main book. So is there a way for them to have a command button "Complete", that would move the active sheet they have filled out in "Workorders" into the "Completed Workorders" book. Either keep it open in the background, so they never see it, or if it can open, move the sheet, and close back.
thank you for your help, and i do hope it is possible.




 Answers:

Insert a button on the workbook and assign this code to the button, make sure to change the filename path to yours:
Private Sub CommandButton1_Click()
    On Error Resume Next
    Dim sheetIndex As Integer
    sheetIndex = 1
    Application.ScreenUpdating = False
    Workbooks.Open Filename:="C:\YourPath\Completed Workorders.xlsm"
    Windows("Workorders.xlsm").Activate
    ActiveSheet.Select
    ActiveSheet.Copy Before:=Workbooks("Completed Workorders.xlsm").Sheets(sheetIndex)
    sheetIndex = sheetIndex + 1

    ActiveWorkbook.Save
    Windows("Completed Workorders.xlsm").Close
    Application.DisplayAlerts = False
    ActiveSheet.Delete
    Application.DisplayAlerts = True
    Application.ScreenUpdating = True
End Sub

Commentaires

Posts les plus consultés de ce blog

XAJAX with PHP – The future of web development

XAJAX with PHP – The future of web development

Database connection pooling in ADO.Net