Situation: There is an Excel file-original report on six different computers. The operator opens it and sees an empty table in front of him, fills it in, the macro that is triggered after each change saves the book to the network folder as a report-copy named data_machine_change.xls. At the end of the shift, the operator closes the book and the next operator, opening the same report-original again, sees the empty table again.

Problem: The problem is that if the operator accidentally closes the original report, he must open the already created copy in the network storage. But. If he starts to change the copy already, the report-copy should not be saved to the server, but save the changes to the book that is open.

Question: in what way, inside vba is it better to determine what the original or copy is open to?

    1 answer 1

    You can identify by file name, because the names of the original and copies are different. The name of the parent of the active sheet, i.e. active book name:

    Sub NameBook() Dim sName As String sName = ActiveSheet.Parent.Name Debug.Print sName End Sub 

    Knowing the name, you can set the condition for saving:

     Sub ToSaveChanges() Dim sName As String sName = "имя_ΠΎΡ€ΠΈΠ³ΠΈΠ½Π°Π»Π°.xlsm" ' имя ΠΊΠ½ΠΈΠ³ΠΈ-ΠΎΡ€ΠΈΠ³ΠΈΠ½Π°Π»Π° With ActiveSheet.Parent If sName = .Name Then ' ΠΎΡ‚ΠΊΡ€Ρ‹Ρ‚ ΠΎΡ€ΠΈΠ³ΠΈΠ½Π°Π» ' здСсь ΠΊΠΎΠ΄ сохранСния Π½ΠΎΠ²ΠΎΠΉ ΠΊΠΎΠΏΠΈΠΈ Else ' ΠΎΡ‚ΠΊΡ€Ρ‹Ρ‚Π° копия .Save ' сохраняСм измСнСния Π² ΠΊΠΎΠΏΠΈΠΈ End If End With End Sub