【问题标题】:Printscreen from SAP by VBA来自 SAP by VBA 的 Printscreen
【发布时间】:2015-11-06 12:51:00
【问题描述】:

我想用 VBA 制作打印屏幕,但不幸的是我只得到了 VBA 的屏幕。

如何以正确的方式做到这一点?

请在下面找到我的脚本:

Sub mb()
Set SapGuiAuto = GetObject("SAPGUI")  'Get the SAP GUI Scripting object
  Set SAPApp = SapGuiAuto.GetScriptingEngine 'Get the currently running SAP GUI
  Set SAPCon = SAPApp.Children(0) 'Get the first system that is currently connected
  Set session = SAPCon.Children(0)

session.findbyId("wnd[0]").maximize
session.findbyId("wnd[0]/tbar[0]/okcd").Text = "/n"
session.findbyId("wnd[0]").sendVKey 0
session.findbyId("wnd[0]/tbar[0]/okcd").Text = "fs10n"
session.findbyId("wnd[0]").sendVKey 0
session.findbyId("wnd[0]/usr/ctxtSO_SAKNR-LOW").Text = Cells(5, 2)
session.findbyId("wnd[0]/usr/ctxtSO_BUKRS-LOW").Text = Cells(5, 3)
session.findbyId("wnd[0]/usr/txtGP_GJAHR").Text = Cells(5, 4)
session.findbyId("wnd[0]/usr/txtGP_GJAHR").SetFocus
session.findbyId("wnd[0]/usr/txtGP_GJAHR").caretPosition = 4
session.findbyId("wnd[0]/tbar[1]/btn[8]").press
'session.findById("wnd[0]/usr/cntlFDBL_BALANCE_CONTAINER/shellcont/shell").pressToolbarContextButton "&MB_EXPORT"
'session.findById("wnd[0]/usr/cntlFDBL_BALANCE_CONTAINER/shellcont/shell").selectContextMenuItem "&HTML"
session.findbyId("wnd[0]/usr/cntlFDBL_BALANCE_CONTAINER/shellcont/shell").setCurrentCell Cells(5, 5), "BALANCE_CUM"


AppActivate
Application.SendKeys "(%{1068})"
DoEvents
Cells(1, 1).Select
ActiveSheet.Paste

【问题讨论】:

    标签: excel vba sap printscreen


    【解决方案1】:

    Sendkeys 非常不可靠,过去让我很沮丧。这是我使用的:

    在 vba 模块的顶部放置这些行

    Option Explicit
    
    Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal _
    bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
    
    Private Const KEYEVENTF_KEYUP = &H2
    Private Const VK_SNAPSHOT = &H2C
    Private Const VK_MENU = &H12
    

    然后粘贴这个 sub 并调用它:

    Sub PrintScreen()
        keybd_event VK_SNAPSHOT, 1, 0, 0
    End Sub
    

    干杯

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-24
      • 2012-05-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多