从excel vba连接到PCOMM

发布于:2025-02-10 ⋅ 阅读:(66) ⋅ 点赞:(0)
Private Declare Sub keybd_event Lib "user32.dll" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)

Public Screen_name As String
Public Screen_name As String
Public autECLSession As Object 
Public autECLPS As Object 
Public autECLOIA As Object 

Sub runcmd()
Dim Session_name
Session_name="A"
Screen_name="Session " & Session_name
Set autECLSession = CreateObject("pcomm.auteclsession") 
Set autECLPS = CreateObject("Pcomm.auteclps") 
Set autECLOIA = CreateObject("Pcomm.autecloia") 
autECLSession.SetConnectionByName (Session_name) 
autECLOIA.SetConnectionByName (Session_name) 

'Customize the screen size
Dim autECLWinObj As Object
set autECLWinObj = CreateObject("Pcomm.autECLWinMetrics") 
autECLWinObj.SetConnectionByName (Session_name) 
autECLWinObj.Width = 976
autECLWinObj.Height = 741
Set autECLWinObj = Nothing

autECLOIA.WaitForAppAvailable (10000)
X_Pos = 18
Y_Pos = 7
autECLSession.autECLPS.SetCursorPos X_Pos Y_Pos
autECLSession.autECLPS.SendKeys "dspjob"
autECLSession.autECLPS.SendKeys "[Enter]"
autECLSession.autECLPS.Wait 500

Capture_Screen ("dspjob")

X_Pos = 3
Y_Pos = 9
sLen = 10
JobName = autECLSession.autECLPS.GetText(X_Pos, Y_Pos,sLen)
Worksheets("Main").Cells(3,2).Value = "Job name is " & JobName

autECLSession.autECLPS.SendKeys "[pf12]"
autECLSession.autECLPS.Wait 1000

AppActivate Screen_name
End Sub

Function Capture_Screen(strMsg)
Application.CutCopyMode = False
AppActivate Screen_name
call keydb_events(vbKeySnapshot,1,1,1)
DoEvents
ScreenShot_Folder="C:\temp"
Pic_Path=ScreenShot_Folder&"\"&Replace(Replace(Now,"/","_"),".","_")&strMsg&".jpg"
Application.ScreenUpdating=False
Application.DisplayAlerts=False
Application.Wait(Now_TimeValue("0:00:2"))
With Charts.Add
 .Paste
 .Export Pic_Path,FilterName:="jpg"
 .Delete
End With
Application.DisplayAlerts=True
Application.ScreenUpdating=True
End Function




可参考资料:

Host Access Class Library Automation Objects

IBM Documentation