|
我最近在学习封装,在封装中遇到些问题,搜索了一些资料后也无法解决。
比如我要封装这么一段:
sub t()
dim str as string
str=thisworkbook.path
msgbox str
按照论坛提供的方法修改为:
sub t()
dim str as string
str=xlapp.thisworkbook.path
msgbox str
这样的加载后得到的提示是方法作用于对象失败。
但是我要是把这个路径改成str=xlapp.StartupPath却能加载成功,说明其他的部分是写正确了的。
请达人指定thisworkbook.path怎么封装。
其他的代码,如下:
Public xlApp As Excel.Application '声明变量xlapp,它代表Excel就用程序
Dim ButtonEvent As cbEvents, OnlyEvents As Collection
Public Sub CreateToolbarButtons() '创建菜单
Dim btNew As Office.CommandBarButton ', SubMenu As Office.CommandBarControl
Set btNew = xlApp.CommandBars(1).Controls.Add(msoControlButton, , , , True)
With btNew
.Style = msoButtonIconAndCaption
.FaceId = 483
.Caption = "测试封装"
End With
Set ButtonEvent = New cbEvents
Set ButtonEvent.cbBtn = btNew
End Sub
Public WithEvents cbBtn As CommandBarButton
Private Sub cbBtn_Click(ByVal Ctrl As Office.CommandBarButton, CancelDefault As Boolean) '单击按钮时执行
Call test2
CancelDefault = True
End Sub
test.rar
(4.26 KB, 下载次数: 34)
|
|