我在excel中有一个子,需要通过访问来调用。Excel VBA
Public Function testme(value As String) As String
Dim xlpath As String
Dim concate As String
xlpath=ActiveWorkbook.Path
value = ActiveWorkbook.Name
concate = xlpath & "\" & value
Let testme = concate
End Function
我需要在一种访问方法中调用上述方法。如何调用它。
Sub Connect1()
Dim xlApp As Variant
'Set xlApp = CreateObject("Excel.Application")
'this will launch a blank copy of excel; you'll have to load workbooks
'xlApp.Visible = True
Set xlApp = GetObject(, "Excel.Application")
Let ans = xlApp.Application.Run("MyXLVBAProject.MyXLVBAModule.testme", 400)
'here ans has the string "500"
End Sub
您可能需要使用Excel对象模型中的Application.Run。您为宏名称传递一个字符串,例如“ QuickRDA.JavaCallBacks.GetQuickTab”,其中QuickRDA是Excel VBA项目的名称,JavaCallBacks是该VBA项目中VBA模块的名称,而GetQuickTab是该VBA项目的名称。该VBA模块中的功能。
在访问中
Sub Connect()
Dim xlApp As Variant
Set xlApp = GetObject(, "Excel.Application")
'this will connect to an already open copy of excel, a bit easier for quick & dirty testing
Let ans = xlApp.Application.Run("MyXLVBAProject.MyXLVBAModule.testme")
End Sub
在Excel中
Public Function testme() As String
Dim xlpath As String
Dim concate As String
Dim value as String
xlpath = ActiveWorkbook.Path
value = ActiveWorkbook.Name
concate = xlpath & "\" & value
Let testme = concate
End Function
-或简单地-
Public Function testme() As String
Let testme = ActiveWorkbook.FullName
End Function
请记住,在Excel中,功能testme应该放在名称为MyXLVBAModule的模块中,而包含该模块的项目应称为MyXLVBAProject。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句