慕哥9229398
VBA的代码和vbs、js的代码虽然在语法有相似之处,但是结构完全不一样,VBA为编译代码,脚本为解释代码,两者不能实现直接交互,只能通过间接交互实现这里通过VBScript修改浏览器标题,触发VB内部的TitleChange而实现交互网页代码:<a onclick=VBScript:document.title="VB:test('X','Y','Z')">文字</a>窗体代码:Option Compare TextPrivate Function Test(S1, S2, S3)MsgBox S1 & S2 & S3End FunctionPrivate Sub Form_Load()WebBrowser1.Navigate "e:\1.htm"End SubPrivate Sub WebBrowser1_TitleChange(ByVal Text As String)If Left(Text, 3) = "VB:" ThenDim s As String, fncName As String, l As Long, argss = Mid(Text, 4)s = Replace(s, "(", " ")s = Replace(s, ")", " ")l = InStr(s, " ")fncName = Trim(Left(s, l - 1))args = Split(Mid(s, l), ",")For i = 0 To UBound(args)args(i) = Trim(args(i))NextSelect Case fncNameCase "test"Test args(0), args(1), args(2)End SelectElseCaption = TextEnd IfEnd Sub