You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

SAP导出PDF代码触发Runtime Error 438,求修改提示

SAP新版环境下PDF导出代码报错(Runtime Error 438)的修改提示

问题背景

以下VBA代码用于从SAP导出PDF文件,在旧版SAP环境中可正常执行,但在新版SAP中,运行到Browserhandle.locationURL语句时触发Runtime Error 438:对象不支持该属性或方法错误:

Call SAPopen(SystemName, SystemID, TransID)
session.findById("wnd[0]").maximize

For i = 6 To lastInv

    invRef = Cells(i, 2)
    invName = Cells(i, 3)
    fileName = fPath & invName & ".pdf"
    If FileExists(fileName) = True Then fileName = fPath & invName & "i" & ".pdf"

    session.findById("wnd[0]/usr/ctxtVBRK-VBELN").Text = invRef
    session.findById("wnd[0]/mbar/menu[0]/menu[11]").Select
    
    If session.ActiveWindow.Name = "wnd[0]" Then
        Message = "No output exists"
        GoTo WriteMsg
    End If
    
    session.findById("wnd[1]/usr/tblSAPLVMSGTABCONTROL").getAbsoluteRow(0).Selected = True
    session.findById("wnd[1]/tbar[0]/btn[37]").press
    
    If session.ActiveWindow.Name = "wnd[1]" Then
        Message = "No output could be opened"
        GoTo WriteMsg
    End If
    
    session.findById("wnd[0]/tbar[0]/okcd").Text = "pdf!"
    session.findById("wnd[0]").sendVKey 0
    
    
    pdfLocL = session.findById("wnd[1]/usr/cntlHTML/shellcont/shell").Browserhandle.locationURL
    pdfLocStart = InStr(pdfLocL, "C:")
    pdfLocS = Mid(pdfLocL, pdfLocStart, 9999)
    
    Set FSO = CreateObject("Scripting.FileSystemObject")
    FSO.copyfile pdfLocS, fileName
    
    If FileExists(fileName) = True Then Message = "Invoice saved" Else Message = "Invoice not saved"
    
    session.findById("wnd[1]").Close
    session.findById("wnd[0]/tbar[0]/btn[3]").press
    session.findById("wnd[1]").Close
    Set FSO = Nothing

修改方向提示

  • 验证SAP控件路径变更:新版SAP可能调整了PDF预览窗口的HTML控件层级或命名,使用SAP自带的「SAP GUI Scripting Tracker」工具,实时捕获当前窗口的控件结构,确认Browserhandle所属控件的实际路径是否与代码中一致。
  • 替换PDF路径获取逻辑:若Browserhandle对象的locationURL属性已被移除,尝试通过控件的Document对象获取路径,示例代码:
    Dim htmlDocument As Object
    Set htmlDocument = session.findById("wnd[1]/usr/cntlHTML/shellcont/shell").Document
    pdfLocL = htmlDocument.URL ' 或尝试 htmlDocument.location.href
    
  • 改用SAP标准导出方式:避免依赖浏览器控件的私有属性,通过配置SAP输出类型(如将输出直接发送到本地文件)、调用后台导出作业,或使用ABAP函数(如GUI_DOWNLOAD)完成PDF导出,这种方式兼容性更强。
  • 同步SAP GUI组件版本:确保客户端安装的SAP GUI及Scripting组件与服务器端SAP版本匹配,旧版组件在新版环境中可能缺失部分属性支持。
  • 临时模拟手动保存:若上述方案暂时无法实现,可通过模拟键盘操作触发PDF保存对话框,再用SendKeys输入目标文件名完成保存(注:该方式稳定性受系统环境影响较大)。

内容的提问来源于stack exchange,提问作者Nureton

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.25 01:45:30