1

I have a workbook sheet which runs a macro from another workbook. The functions run fine. But the workbook having the macro (which is run from the active sheet) gets open and does not close through vba. I have to manually close it. What can i do to make it close through the code itself so that the other file does remain open

The code is given below

Sub UpdateStockRegister()

    Application.DisplayAlerts = False
    Application.ScreenUpdating = False

    Application.Run "'F:\ITEMS.xlsm'!UniqueTransactionItems"
    ActiveWorkbook.Close

    Dim wbSource As Workbook
    Dim wbTarget As Workbook
    Set wbTarget = ThisWorkbook

    Set wbSource = Workbooks.Open("F:\ITEM REPORT.xlsm")
    wbSource.Sheets("TRANSACTION DATA").Copy After:=wbTarget.Sheets("STOCK REGISTER")
    wbSource.Close Savechanges = True

    Sheets("TRANSACTION DATA").Select
    ActiveSheet.Range("A1").EntireRow.Delete
    Range("A1").Select

    Sheets("TRANSACTION DATA").Select
    ActiveSheet.Range("A1").EntireRow.Delete
    Range("A1:A15000,B1:B15000,C1:C15000,D1:D15000,E1:E15000,F1:F15000").Select
    Selection.Copy
    Sheets("STOCK REGISTER").Select
    Range("A8").Select
    Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
        Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
        xlNone, SkipBlanks:=False, Transpose:=False
        Selection.HorizontalAlignment = xlCenter
        Selection.VerticalAlignment = xlCenter
        Range("A8").Select

    Sheets("TRANSACTION DATA").Delete
    ActiveWorkbook.Save
End Sub
Community
  • 1
  • 1

0 Answers0