Click here to Skip to main content
15,897,226 members
Please Sign up or sign in to vote.
3.80/5 (3 votes)
See more:
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
Posted

Let's give Google[^] a try.
 
Share this answer
 
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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900