Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 3899|回复: 1

vba里 函数和过程怎么传递对象变量

[复制链接]
发表于 2019-5-9 01:16 | 显示全部楼层 |阅读模式
1学分
请教各位
比如下面这段代码 如何把定义的对象ie传递给函数

Sub test()
Set ie = CreateObject("InternetExplorer.Application")
          With ie
Debug.Print txt(classname)
End Sub

Function txt(aa As String)
txt = .document.getelementbyclassname(aa).innertext
End Function

反过来又是如何操作的? 比如下面这段

Sub test()
ie("www.baidu.com")
.document.getelementbyid("password").value=112233
End Sub

Function ie(a As String)
Set ie = CreateObject("InternetExplorer.Application")
          With ie
.Navigate a
End Function

发表于 2019-5-9 10:43 | 显示全部楼层
对象的类型是object。你第二个过程的代码引用写的也不对(第一个我没测试),正确的引用是这样的:
Sub test()
Call ie("www.baidu.com")
'.document.getelementbyid("password").Value = 112233
End Sub

Sub ie(a As String)
Dim aaa As Object
Set aaa = CreateObject("InternetExplorer.Application")
aaa.Navigate a
End Sub
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-5-28 17:21 , Processed in 0.210550 second(s), 5 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表