0
votes

I have a simple macro saving an excel file every 30 seconds (in excel 2003). I have two excel files open running the same macro. The problem is when they save the workbook 'pops' up infront of the other workbooks I have open.

This is extremely annoying, does anyone know how to prevent this behavior..?

Public Sub macro_save()
    Application.EnableEvents = False
    Application.DisplayAlerts = False

    ThisWorkbook.Save
    If Second(Now) < 30 Then
        Application.OnTime VBA.TimeSerial(Hour(Now), Minute(Now), 30), "macro_save"
    Else
        Application.OnTime VBA.TimeSerial(Hour(Now), Minute(Now) + 1, 0), "macro_save"
    End If

    Application.EnableEvents = True
    Application.DisplayAlerts = True
End Sub
1

1 Answers

2
votes

Add this lines as first line in your sub:

Dim WBactive as Workbook
Set WBactive = Activeworkbook

and before End Sub add this line

WBactive.Activate

You could additionally add as your third line:

Application.ScreenUpdating = False

but remember to set it reverse before ending your sub:

Application.ScreenUpdating = True