oleobject add 方法的函数回调问题

kris2010 2013-07-03 11:34:58
不太清楚怎么表达, 请忽略标题
具体就是在function方法中使用 activeSheet.OLEObject.add 方法新添加一个oleobject对象无法继续执行下去.
如果在单独的sub中使用这个方法可以, 而且必须是宏运行的方式, 函数调用也是不行的.
详细代码:
Function BAR_CODE(codeValue)
Dim vtrue
Dim barObj
If IsEmpty(codeValue) Then
Exit Function
End If

If TypeName(codeValue) = "Range" Then
vtrue = codeValue.Value
Else
vtrue = codeValue
End If
//call insertBarCode
With ActiveSheet
Set tmp = .OLEObjects.Add(ClassType:="BARCODE.BarCodeCtrl.1")
With tmp
.Object.Style = 7
.Object.Value = "11234325"
.Width = 100
.Height = 50
.Top = 10
.Left = 10
End With
End With
If TypeName(barObj) = "Object" Then
With barObj
.Object.Style = 7
.Object.Value = "11234325"
.Width = 100
.Height = 50
.Top = 10
.Left = 10
End With
End If
End Function

Sub insertBarCode()
With ActiveSheet
Set tmp = .OLEObjects.Add(ClassType:="BARCODE.BarCodeCtrl.1")
With tmp
.Object.Style = 7
.Object.Value = "11234325"
.Width = 100
.Height = 50
.Top = 10
.Left = 10
End With
End With
End Sub


单独调试insertbarcode 没有问题, 但通过函数bar_code是没法调用的.
我知道oleobject Add方法会暂时跳出当前进程, 通过ole server 创建.
怎么才能如单独运行宏一样的返回呢?
...全文
335 回复 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

5,172

社区成员

发帖
与我相关
我的任务
社区描述
其他开发语言 Office开发/ VBA
社区管理员
  • Office开发/ VBA社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧