I have a macro that interfaces with SAP. The SAP portion is for it to run a report and open it in Excel. Excel takes over and activates the workbook, then saves it in a location and converts the file type from .MHTML to .xlsx.
When I step through the macro using F8 along the way, I have no issues. The macro works as expected. When I run the macro, however, it hits an error because my personal workbook somehow gets opened as read-only and I have to negotiate the message box saying that my personal workbook is locked for editing. Again, this is ONLY when I run the macro and does not appear when I step through it.
Here is the code:
Here is where the problem occurs:
The blue piece of code is where SAP goes ahead and saves the file which opens automatically. When the file opens at that point, I get the dialog box saying the the personal workbook is locked for editing. Since that message box is open, I cannot perform the bit of code that is highlighted in red, which is technically where the macro fails.
Any insight as to why that is and how to get around it?
I have a number of macros in my personal workbook that need to be preserved and on hand for other tasks, for whatever that is worth.
Thank you for your assistance.
When I step through the macro using F8 along the way, I have no issues. The macro works as expected. When I run the macro, however, it hits an error because my personal workbook somehow gets opened as read-only and I have to negotiate the message box saying that my personal workbook is locked for editing. Again, this is ONLY when I run the macro and does not appear when I step through it.
Here is the code:
Code:
Sub SAPScript()Application.DisplayAlerts = False
If Not IsObject(SAPGuiApp) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set SAPGuiApp = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(connection) Then
Set connection = SAPGuiApp.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
session.findById("wnd[0]").resizeWorkingPane 167, 36, False
session.findById("wnd[0]/tbar[0]/okcd").text = "/NZSD_INFOREQ_RPT"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/radP_ALL").select
session.findById("wnd[0]/usr/ctxtSO_DATES-LOW").text = Date - 30
session.findById("wnd[0]/usr/ctxtSO_DATES-HIGH").text = Date
session.findById("wnd[0]/usr/radP_ALL").setFocus
session.findById("wnd[0]").sendVKey 8
session.findById("wnd[0]").resizeWorkingPane 167, 36, False
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").contextMenu
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").selectContextMenuItem "&XXL"
session.findById("wnd[1]/tbar[0]/btn[0]").press
session.findById("wnd[1]/usr/ctxtDY_PATH").text = "I:\Bryan Voskuil\Product Operations\Product Service Representatives\Workflow Reporting\"
session.findById("wnd[1]/usr/ctxtDY_FILENAME").text = "export.MHTML"
session.findById("wnd[1]/tbar[0]/btn[11]").press
Application.Wait (Now + TimeValue("00:00:05"))
Workbooks("Export.MHTML").Activate
ActiveWorkbook.SaveAs Filename:= _
"I:\Product Service Representatives\Workflow Reporting\Power BI Data\Rolling_30_Workflow_PowerBI.xlsx" _
, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
Application.DisplayAlerts = True
ActiveWorkbook.Close
End Sub
Here is where the problem occurs:
Code:
session.findById("wnd[1]/usr/ctxtDY_PATH").text = "I:\Bryan Voskuil\Product Operations\Product Service Representatives\Workflow Reporting\"session.findById("wnd[1]/usr/ctxtDY_FILENAME").text = "export.MHTML"
[B][COLOR=#0000ff]session.findById("wnd[1]/tbar[0]/btn[11]").press[/COLOR][/B]
Application.Wait (Now + TimeValue("00:00:05"))
[COLOR=#ff0000][B]Workbooks("Export.MHTML").Activate[/B][/COLOR]
The blue piece of code is where SAP goes ahead and saves the file which opens automatically. When the file opens at that point, I get the dialog box saying the the personal workbook is locked for editing. Since that message box is open, I cannot perform the bit of code that is highlighted in red, which is technically where the macro fails.
Any insight as to why that is and how to get around it?
I have a number of macros in my personal workbook that need to be preserved and on hand for other tasks, for whatever that is worth.
Thank you for your assistance.