是否可以在Excel VBA中使用Wscript运行C#编译器csc? [英] Is it possible to run C# compiler csc using Wscript in Excel VBA?
问题描述
您好b $ b
我希望有人可以帮助我。
是否可以使用WScript运行c#命令行编译器?
我需要从Excel VBA动态编译.cs文件到DLL。我认为有些事情会起作用,但事实并非如此。有没有人知道是否可能,如果有的话我会感激任何帮助/代码片段。
Sub Macro1()
Dim wsh As Object
设置wsh = VBA.CreateObject(WScript.Shell)
Dim waitOnReturn As Boolean:waitOnReturn = True
Dim windowStyle As Integer:windowStyle = 1
wsh.Runcsc / target:library /out:MathLibrary.DLL Add.cs Mult .cs,windowStyle,waitOnReturn
End Sub
Hi
I'm hoping somebody can help me.
Is it possible to use WScript to run the c# command line compiler?
I have a need to compile .cs files to DLLs on the fly from Excel VBA. I thought something along the lines of this would work but it doesn't. Does anybody know whether it is possible and if so i'd be grateful for any help / code snippets.
Sub Macro1()
Dim wsh As Object
Set wsh = VBA.CreateObject("WScript.Shell")
Dim waitOnReturn As Boolean: waitOnReturn = True
Dim windowStyle As Integer: windowStyle = 1
wsh.Run "csc /target:library /out:MathLibrary.DLL Add.cs Mult.cs", windowStyle, waitOnReturn
End Sub
推荐答案
让我们给 Google [< a href =https://www.google.co.uk/#q=calling+an+executable+from+excel+VBAtarget =_ blanktitle =New Window> ^ ] a试试。
Let's give Google[^] a try.
我需要以管理员身份运行怀疑
私有声明功能ShellExecute Libshell32.dllAlias ShellExecuteA_
(ByVal hWnd As很长,_
ByVal lpOperation As String,_
ByVal lpFile As String,_
ByVal lpParameters As String,_
ByVal lpDirectory As String,_
ByVal nShowCmd As Long)As Long
Sub RunAsAdmin()
Const SW_NORMAL As Long = 1
ShellExecute Application.hWnd,_
runas,_
c:\windows \ system32 \ cmd.exe,_
,_
c:\windows \ system32,SW_NORMAL
End Sub
I needed to run as an administrator as suspected
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal hWnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long
Sub RunAsAdmin()
Const SW_NORMAL As Long = 1
ShellExecute Application.hWnd, _
"runas", _
"c:\windows\system32\cmd.exe", _
"", _
"c:\windows\system32", SW_NORMAL
End Sub
这篇关于是否可以在Excel VBA中使用Wscript运行C#编译器csc?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!