|
楼主 |
发表于 2024-1-3 09:51
|
显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Sub 按钮2_Click()
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Application.Speech.Speak "今日天气晴朗,不会下雨"
- Dim lastRow&, i&, n&, rowCount&, win
- lastRow = Sheet1.Range("A1").End(xlDown).Row
- If Not IsObject(Applicationa) Then
- Set SapGuiAuto = GetObject("SAPGUI")
- Set Applicationa = SapGuiAuto.GetScriptingEngine
- End If
- If Not IsObject(Connection) Then
- Set Connection = Applicationa.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 Applicationa, "on"
- End If
-
- If Not IsObject(win) Then
- Set win = session.findById("wnd[0]")
- End If
- session.findById("wnd[0]/tbar[0]/okcd").Text = "/NMIGO"
- session.findById("wnd[0]").sendVKey 0
-
- win.FindByName("GODYNPRO-ACTION", "GuiComboBox").Key = "A07"
- win.FindByName("GODYNPRO-REFDOC", "GuiComboBox").Key = "R10"
- win.FindByName("GODEFAULT_TV-BWART", "GuiCTextField").Text = "ZK2"
- session.findById("wnd[0]").sendVKey 0
-
- ' For n = 0 To Application.WorksheetFunction.RoundUp((lastRow - 1) / rowCount, 0)
- rowCount = win.FindByName("SAPLMIGOTV_GOITEM", "GuiTableControl").VisibleRowCount
- For n = 0 To Application.WorksheetFunction.RoundUp((lastRow - 1) / rowCount, 0)
-
- For i = 0 To rowCount - 1
- If rowCount * n + 2 + i > lastRow Then Exit For
- win.FindByName("SAPLMIGOTV_GOITEM", "GuiTableControl").GetCell(i, 1).Text = Sheet1.Cells(rowCount * n + 2 + i, 1).Text
- win.FindByName("SAPLMIGOTV_GOITEM", "GuiTableControl").GetCell(i, 3).Text = Sheet1.Cells(rowCount * n + 2 + i, 3).Text
- win.FindByName("SAPLMIGOTV_GOITEM", "GuiTableControl").GetCell(i, 4).Text = Sheet1.Cells(rowCount * n + 2 + i, 4).Text
- win.FindByName("SAPLMIGOTV_GOITEM", "GuiTableControl").GetCell(i, 2).Text = Sheet1.Cells(rowCount * n + 2 + i, 2).Text
- Next i
- win.FindByName("SAPLMIGOTV_GOITEM", "GuiTableControl").GetCell(0, 1).SetFocus
- win.sendVKey 0
-
- For i = 0 To rowCount - 1
- If rowCount * n + 2 + i > lastRow Then Exit For
- win.FindByName("SAPLMIGOTV_GOITEM", "GuiTableControl").GetCell(i, 8).Text = Sheet1.Cells(rowCount * n + 2 + i, 7).Text
- win.FindByName("SAPLMIGOTV_GOITEM", "GuiTableControl").GetCell(i, 5).Text = Sheet1.Cells(rowCount * n + 2 + i, 5).Text
- win.FindByName("SAPLMIGOTV_GOITEM", "GuiTableControl").GetCell(i, 7).Text = Sheet1.Cells(rowCount * n + 2 + i, 6).Text
- Next i
- win.FindByName("SAPLMIGOTV_GOITEM", "GuiTableControl").GetCell(0, 5).SetFocus
- session.findById("wnd[0]/tbar[0]/btn[83]").press
-
- Next n
- session.findById("wnd[0]/tbar[1]/btn[7]").press
- ' session.findById("wnd[0]/tbar[1]/btn[23]").press
- Application.Speech.Speak "今日天气晴朗,确定不会下雨"
-
- Application.ScreenUpdating = True
- Application.DisplayAlerts = True
- End Sub
复制代码
这个方法好,只是每第14项数据丢失了
|
|