簡體   English   中英

VBA從SAP打印屏幕

[英]Printscreen from SAP by VBA

我想通過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

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 PrintScreen()
    keybd_event VK_SNAPSHOT, 1, 0, 0
End Sub

干杯

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM