Reputation: 109
I'm trying to disable the message box: "There's already data here. Do you want to replace it?"
I've tried to disable VBA alerts, but without success.
First, I went to Excel Settings> Advanced > Alert before overwriting cells, but it didn't work.
I've also tried to place the statement in my code:
Application.DisplayAlerts = False
But, I'm getting multiple errors depending where I place the statement.
Since I already have an application as part of my code, I tried also to change the application name to the same name as the variable is set in my code, but I'm getting: " The enumerator of the collection cannot find en element with the specified index.
SapGuiAuto.GetScriptingEngine.DisplayAlerts = False
Since this is a huge code I will post only the beginning of it. Please see below:
Sub Macro5()
Dim SapGui
Dim Application
Dim Connection
Dim Session
Dim WSHShell
If Not IsObject(Application) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set Application = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(Connection) Then
Set Connection = Application.Children(0)
End If
If Not IsObject(Session) Then
Set Session = Connection.Children(0)
End If
If IsObject(WScript) Then
WScript.ConnectObject Session, "on"
WScript.ConnectObject Application, "on"
End If
SapGuiAuto.GetScriptingEngine.DisplayAlerts = False
End Sub
Upvotes: 0
Views: 3814
Reputation: 1
That's SAP message, not excel, you should probably add a double SAP command to overwrite the excel file after saving it
session.findById("wnd[1]").sendVKey 0
session.findById("wnd[1]/tbar[0]/btn[0]").press
Upvotes: 0
Reputation: 179
Try adding the below line at the beginning of your code:
Application.AlertBeforeOverwriting = False
Then you can do the opposite at the end of your code to revert this setting.
Upvotes: 1