2301_81468091 2023-12-19 04:06 采纳率: 33.3%
浏览 18
已结题

追加问题电脑锁屏时vba复制数据,不能到SAP怎么解决

追加问题电脑锁屏时vba复制数据,不能到SAP怎么解决
下面使用sendmessage需要怎么修改?

#End If
Private Declare PtrSafe Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As LongPtr, ByVal wMsg As Long, ByVal wParam As LongPtr, lParam As Any) As LongPtr
 Private Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As LongPtr
Private Declare PtrSafe Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As LongPtr, ByVal hWnd2 As LongPtr, ByVal lpsz1 As String, ByVal lpsz2 As String) As LongPtr

Private Const WM_PASTE = &H302

Sub PasteDataToSAP()
    Dim hh As Long
    Dim hwnd As LongPtr

    hh = Range("a2").CurrentRegion.Rows.Count
    hwnd = FindWindow(543690, "Multiple Selection for Change Number") ' 将"SAP窗口标题"替换为实际的窗口标题

    Range("a2:a" & hh).Copy
    
    session.findById("wnd[0]").maximize
    session.findById("wnd[0]/tbar[0]/okcd").Text = "/NSE16"
    session.findById("wnd[0]").sendVKey 0
    session.findById("wnd[0]/usr/ctxtDATABROWSE-TABLENAME").Text = "AEOI"
    session.findById("wnd[0]").sendVKey 0
    session.findById("wnd[0]/usr/btn%_I1_%_APP_%-VALU_PUSH").press

    Dim hwndEdit As LongPtr
    hwndEdit = FindWindowEx(hwnd, 0, "SAP_FRONTEND_SESSION", vbNullString)
    SendMessage hwndEdit, WM_PASTE, 0, 0 ' 使用SendMessage函数进行粘贴操作

img

img

img

img


  • 写回答

11条回答 默认 最新

  • 叫兽-郭老师 Java领域新星创作者 2023-12-19 04:24
    关注

    由人工智能和答主提供,可以参考如下,如果回答的不正确,及时评论区回复,我追加回答,谢谢。


    在VBA中,使用SendMessage函数发送粘贴操作时,需要将参数类型转换为Long。以下是修改后的代码:

    Private Declare PtrSafe Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As LongPtr, ByVal wMsg As Long, ByVal wParam As LongPtr, lParam As Any) As LongPtr
    Private Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As LongPtr
    Private Declare PtrSafe Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As LongPtr, ByVal hWnd2 As LongPtr, ByVal lpsz1 As String, ByVal lpsz2 As String) As LongPtr
    Private Const WM_PASTE = &H302
    
    Sub PasteDataToSAP()
        Dim hh As Long
        Dim hwnd As LongPtr
        hh = Range("a2").CurrentRegion.Rows.Count
        hwnd = FindWindow(543690, "Multiple Selection for Change Number") ' 将"SAP窗口标题"替换为实际的窗口标题
        Range("a2:a" & hh).Copy
        session.findById("wnd[0]").maximize
        session.findById("wnd[0]/tbar[0]/okcd").Text = "/NSE16"
        session.findById("wnd[0]").sendVKey 0
        session.findById("wnd[0]/usr/ctxtDATABROWSE-TABLENAME").Text = "AEOI"
        session.findById("wnd[0]").sendVKey 0
        session.findById("wnd[0]/usr/btn%_I1_%_APP_%-VALU_PUSH").press
        Dim hwndEdit As LongPtr
        hwndEdit = FindWindowEx(hwnd, 0, "SAP_FRONTEND_SESSION", vbNullString)
        SendMessage hwndEdit, WM_PASTE, 0&, 0 ' 使用SendMessage函数进行粘贴操作
    End Sub
    

    这段代码首先声明了三个函数指针,分别用于调用SendMessage、FindWindow和FindWindowEx。然后在PasteDataToSAP子程序中,通过FindWindow找到SAP窗口的句柄,然后使用FindWindowEx找到编辑框的句柄。最后,使用SendMessage函数发送粘贴消息。

    评论

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 12月20日
  • 赞助了问题酬金15元 12月19日
  • 创建了问题 12月19日

悬赏问题

  • ¥15 mac系统控制台运行npm run serve没问题但是配置文件不识别serve脚本
  • ¥66 换电脑后应用程序报错
  • ¥50 array数据同步问题
  • ¥15 pic16F877a单片机的外部触发中断程序仿真失效
  • ¥15 Matlab插值拟合差分微分规划图论
  • ¥15 keil5 target not created
  • ¥15 C/C++数据与算法请教
  • ¥15 怎么找志同道合的伙伴
  • ¥20 如何让程序ab.eXe自已删除干净硬盘里的本文件自己的ab.eXe文件
  • ¥50 爬虫预算充足,跪巨佬