hi, i want to automate visual studio 2015 from an external VBA to build a solution, and i do not know what should i do , automate directly vs compiler or i should automate IDE, who can help me with advice and source code

Recommended Answers

All 31 Replies

Don't know exactly what you mean by "automate visual studio", but these might help.

i want to launch visual studio , open solution build project , all from an external VBA(visual basic for application ) , i dont know if it is the best solution or i can directly automate Vs compiler without starting the IDE

automate Vs compiler ( commande line ) to build my solution

i mean by automate vs that i want to open launch vs,open solution , build it

You can run devenv.exe and build your project from the command line. Type

devenv /?

to get the command line arguments/switches. You'll have to spawn it as an external process. Use the vba Shell call to do that

ret = Shell("command line with args", vbNormalFocus)

thank you jim , but can you explain more plz gger.png
i want to automate visual studio compiler to build in tha hard disk visual studio solution all from external VBA

I see you need to get your command line working then we can share that command and help you put that into your Line 2.

i put the devnex , batch file and the solution in the same folder "c:\Program Files\Microsoft Visual Studio 14.0\Common7\IDE"
this is the code of batch file :
echo off

call "C:\Program Files\Microsoft Visual Studio 14.0\VC\bin\vcvars32.bat"
"c:\Program Files\Microsoft Visual Studio 14.0\Common7\IDE\devenv.exe "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\ConsoleApplication8.sln"" /build


it briefly cmd window appear and displays the error below , i dont why it is not visual studio widow that appear
any help pls

Read the message. It says you have a syntax error. I tried

devenv clipjpg.sln /build

on one of my projects and it compiled/built the executable with no problems.

this is my batch file :
echo off

call "C:\Program Files\Microsoft Visual Studio 14.0\VC\bin\vcvars32.bat" x86
devnev.exe /build Release "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\ConsoleApplication8.sln"

and this is VBA command fs.png
when i compile VBA project it displays that devnev.exe is not know as an internal command qsdv.png
i wanted that VS command prompt which compile the solution not "cmd"

i make some modification but i displays command window without building
rfvrv.png zdcv.png

Try Shelling devenv instead of test.bat

yes it starts visual studio sqcdbf.png

i had application build with visual studio and a text file that store time process,
please what is the deffiernce to execute an application build with visual studio , what is the differnce to execute it directly with 2 click and via shell command, because when i execute it via shell VBA the time process in text file does not be modified

I'm not clear on what you are asking but my usual approach when trying to automate something is to do it in stages rather than jumping immediately to the final step. What you are trying to do (from what I gather) is

vba -> batch file -> devenv -> build solution

The first thing I'd do is try running the build directly from the command line

"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe" "d:\my\Documents\Visual Studio Projects\ClipToJPG\ClipToJPG.sln" /build

then check to make sure the solution executable has been created. Once you know that works you can try shelling the same command line from within VBA (delete the solution executable first so you can see if it has been recreated).

Then you can create a simple batch file to do something like launch an app (like calc). Make sure this runs from the command line, then try to execute it from VBA. This will show that you can execute a batch file.

Once that works, try creating a batch file to execute the same vb.net build (although I don't see why you need to add this complication). Try running that from within VBA.

The trick (if you can call it that although it's just basic troubleshooting) is to see where the problem is. If you just throw all the parts together and it doesn't work then it's hard to figure out which part is the problem.

thak you Dr jim, my aim is to build a visual studio solution and run run exe application from VBA, i used batch file in order to lauch Vs compiler , i dont know if it is possible directly through VBA or not , if it is possible let me know to avoide this compilcation pls ,
2) i did what you suggest and it helps me to resolve the problem thank you , but i have an other other question pls , the application that i talk about above store the execution time in a text file fb.png , so when i double clicked it it works normally and store the time process in the text file , but when i use shell command the app is run (result on cmd command ) gger.png but i didn't store the time process in the text file, how can you explain this thank you ,

i used batch file in order to lauch Vs compiler

I still don't understand why you are doing that.

i dont know if it is possible directly through VBA or not

I don't have Microsoft Office so I can't test this so I suppose the best way to find out is to follow my steps above. Make a small test VBA that does nothing but run an exe.

but i didn't store the time process in the text file, how can you explain this

I can't. Mostly because your console application (which somehow has a form) is a black box and you didn't post the code. If you are going to give me the information I need to help in bits and pieces then one of two things is going to happen

  1. You might get an answer but it wiull take a very long time.
  2. I'll get tired of asking for more information and I'll just quit helping.

dr Jim , the whole story in this document

Can you build the exe file from the command line?

Can you build the exe file using the same command but from within vba via the Shell command?

i tried to to build solution through VBA shell a.png
it just start Visual studio and got this error msg aaaa.png

dr my aim is to command visual studio compiler via VBA ( idon't have idea it is possible through shell command, batch file file ...) to build visual studio solution directy without the need to start VS IDE because starting IDE , loading solution , building it took too much time.
any need pls

The command line you are executing with Shell has spaces in it so you have to add extra quotes just like you would if you were running it from the command line. For example, if you ran the following from the command line

C:> C:\Program Files\Folder\test.exe arg1

you would get an error so you would have to type it as

C:> "C:\Program Files\Folder\test.exe" arg1

Inside vba you would have to do

ret = Shell("""C:\Program Files\Folder\test.exe"" arg1", vbHide)

As an afterthought, I still don't understand why you want to do this through vba. Who cares if it takes a while to build it theough the IDE? You only have to do that when the source code changes. You only have to automate something when it has to be done repeatedly. And if you are going to do it through vba, starting your vba app is going to be a manual process anyway (most likely) so what have you gained by adding in the extra step?

Maybe the intentions of the OP are noble. But do I smell something like a virus?

Possibly. I can't see anything useful in what OP is trying to do, but there is nothing overtly malicious either. I'm basically just trying to show him how two simple things work. At this point I think I'll just give up.

dr ddanbe im a debutant student in embedded system field and i dont know of what virus you talk about , im sorry for the disturbance i ask for help because it the first time that i deal with VBA , my VBA is integrated in excel software i wanted to get time process of an adder (i told the you the code source dr jim in a doc file ) and store process time in text file,
this is my attempt dr jim
i found that you are right there is no meaning for rebuilding the same solution with same code source,
from the begining as you remmber i ask to share screen to avoid misunderstanding im sorry, i ask you for the last time dr jim pls can help explain nad help me this problem when i double clik on my application the time process is stored on the text file 1.png
but when i shell the same application through VBA it run but no time process stored 2.png
this is my code source for the application as you see its an adder that store process time

what should i do force shelling storing process time on text file thank you deeply

Back to my question. If you want to know how long it takes to do the add, doing it through vba is pointless. Just run the executable directly. Also, you are just going to get a value of 0 for testing one addition. Even if you put in a loop to do the operation a million times you won't be able to distinguish between the time it takes to do the addition and the time spent on the rest of the loop processing.

As for writing the text file, try putting the full path and file name of the file you want to write. It's entirely possible the file is being created, just not where you expect it to be.

i try your suggestion dr Jim as you see follow the solution is buils with but with problem PDB not found also text file on the specified folder D:\toto.txt is empty
cver.png ejec.png

i thank you deeply for your help , especially Dr Jim :) :) i come to solve my problem :) thanks to God, i add instructon that create file and store simulation time rrr.png
Dr Jim i would be happpy if we keep in touch if it is possible, my email yosri.bensalah@outlook.fr
whish all the best for you :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.