Personal Workbook Locked For Editing *Only* When Running Macro and Not When Stepping Through


New Member
Jul 29, 2013
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:

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/ctxtSO_DATES-LOW").text = Date - 30
session.findById("wnd[0]/usr/ctxtSO_DATES-HIGH").text = Date
session.findById("wnd[0]").sendVKey 8
session.findById("wnd[0]").resizeWorkingPane 167, 36, False
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").selectContextMenuItem "&XXL"
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"
Application.Wait (Now + TimeValue("00:00:05"))
    ActiveWorkbook.SaveAs Filename:= _
        "I:\Product Service Representatives\Workflow Reporting\Power BI Data\Rolling_30_Workflow_PowerBI.xlsx" _
        , FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
Application.DisplayAlerts = True
End Sub
Here is where the problem occurs:

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"
Application.Wait (Now + TimeValue("00:00:05"))
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.

Some videos you may like

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.

Subscribe on YouTube

Watch MrExcel Video

Forum statistics

Latest member

This Week's Hot Topics

  • Turn fraction around
    Hello I need to turn a fraction around, for example I have 1/3 but I need to present as 3/1
  • TIme Clock record reformatting to ???
    Hello All, I'd like some help formatting this (Tbl-A)(Loaded via Power Query) [ATTACH type="full" width="511px" alt="PQdata.png"]22252[/ATTACH]...
  • TextBox Match
    hi, I am having a few issues with my code below, what I need it to do is when they enter a value in textbox8 (QTY) either 1,2 or 3 the 3 textboxes...
  • Using Large function based on Multiple Criteria
    Hello, I can't seem to get a Large formula to work based on two criteria's. I can easily get a oldest value based one value, but I'm struggling...
  • Can you check my code please
    Hi, Im going round in circles with a Compil Error End With Without With Here is the code [CODE=rich] Private Sub...
  • Combining 2 pivot tables into 1 chart
    Hello everyone, My question sounds simple but I do not know the answer. I have 2 pivot tables and 2 charts that go with this. However I want to...