Board logo

标题: [问题求助] vbs调用vba的api函数 [打印本页]

作者: segree    时间: 2023-5-20 18:10     标题: vbs调用vba的api函数

本帖最后由 segree 于 2023-5-20 18:23 编辑

如题:想通过vbs调用vba的api函数,已经在vba里面成功用上获取屏幕坐标颜色数值,想通过vbs脚本调用,不知道怎么调用
  1. Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
  2. Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
  3. Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
  4. '**********************   类型声明   ****************************
  5. Private Type POINTAPI
  6.     x As Long
  7.     y As Long
  8. End Type
  9. Private Sub tmp2()
  10. Debug.Print Hex(pixcolour)
  11. End Sub
  12. Public Function pixcolour() As Long
  13.     Dim pt As POINTAPI
  14.     GetCursorPos pt
  15.     Dim Dc: Dc = GetDC(0)
  16.     pixcolour = GetPixel(Dc, pt.x, pt.y)
  17. End Function
  18. vbs:
  19. "Private Declare Function GetDC Lib ""user32"" (ByVal hwnd As Long) As Long"                                                         & vbCrLf & _
  20. "Private Declare Function GetPixel Lib ""gdi32"" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long"          & vbCrLf & _
  21. " Public Function pixcolour() As Long"        & vbCrLf & _
  22. "Dim pt As POINTAPI: GetCursorPos pt"        & vbCrLf & _
  23. "Dim Dc:Dc = GetDC(0)"                       & vbCrLf & _
  24. "pixcolour = GetPixel(Dc, pt.X, pt.Y)"       & vbCrLf & _
  25. "End Function"                              & vbCrLf & _
复制代码
请问怎么用vbs调用vba的函数呀?vbs脚本上这么写封装的函数对吗?"ublic Function pixcolour() As Long"        & vbCrLf & _    这一行报错:缺少语句 1字符  800A0400
作者: jyswjjgdwtdtj    时间: 2023-5-20 19:19

vbs里Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long这么些肯定是不对的
不过我不知道你是怎么调用vba的
作者: czjt1234    时间: 2023-5-20 19:48

http://demon.tw/programming/vbs-control-mouse.html
作者: jyswjjgdwtdtj    时间: 2023-5-20 21:10

嗯 demon.tw上的博客算是比较好的vbs……“攻略”?
作者: segree    时间: 2023-5-21 01:45

己解决怎么设置
作者: segree    时间: 2023-5-21 11:09

czjt1234 发表于 2023-5-20 19:48


谢谢指点,原来也有收藏,没仔细看,已做成vba函数从vbs调用。




欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2