我有这个vba代码
Dim strpath As String
Dim this As String
strpath = "C:\Users\johbra\Documents\Visual Studio 2010\Projects\WindowsApplication6\WindowsApplication6\bin\Debug\WindowsApplication6.exe"
this = Shell(strpath)
MsgBox this
我在.net程序中也有这个函数
Public Class Form1
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
dothis()
Application.Exit()
End Sub
Function dothis()
Return "HI"
End Function
End Class
我想让vba代码给我一个留言盒,上面写着“HI”。这个是可能的吗?
发布于 2013-08-16 05:18:46
从VBA调用.NET代码的最可接受和最可靠的方法是将.NET类公开为COM类(不需要额外的代码,只需在项目属性中勾选适当的框),然后在VBA项目中添加COM类的引用,这是其他COM类的调用方式,并调用函数。
如果你需要更多的细节,请告诉我如何做到这一点。
发布于 2013-08-16 04:34:52
我认为您需要使用命令行参数来尝试这一点。
比如:
Dim CommandLineArgs As System.Collections.ObjectModel.ReadOnlyCollection(Of String) = My.Application.CommandLineArgs
For i As Integer = 0 To CommandLineArgs.Count - 1
MessageBox.Show(CommandLineArgs(i))
Next
将参数传回VBA脚本;
Console.WriteLine("Message")
可以在VBA代码中捕获控制台结果..。
https://stackoverflow.com/questions/18273397
复制相似问题