Runing GAMS Using Excel as front-end (VBA)

239 views
Skip to first unread message

Munier Elsherif

unread,
Sep 1, 2014, 1:40:47 PM9/1/14
to gams...@googlegroups.com
Hi, anyone have managed to run GAMS using VBA macro, I do have a model where I use GDX to link excel with GAMS and l want to run the model through excel

any feedback to this would be appreciated


Claudio Delpino

unread,
Sep 1, 2014, 4:41:40 PM9/1/14
to gams...@googlegroups.com
I have used this code in the past, probably mixes a couple of techniques (can't even remember, but I think waitOnReturn and windowStyle can be deleted, and I don't remember what %comspec% does), but there are a lot of VBA forums detailing the workings of running external applications.

Dim gmsfile As String
Dim gdxfile As String
Dim wsh As Object
Set wsh = VBA.CreateObject("WScript.Shell")
Dim waitOnReturn As Boolean: waitOnReturn = True
Dim windowStyle As Integer: windowStyle = 1

wsh.Run "%comspec% /k gams """ & gmsfile & """ GDX=""" & gdxfile & """"




On Mon, Sep 1, 2014 at 2:40 PM, Munier Elsherif <muniere...@gmail.com> wrote:
Hi, anyone have managed to run GAMS using VBA macro, I do have a model where I use GDX to link excel with GAMS and l want to run the model through excel

any feedback to this would be appreciated


--
You received this message because you are subscribed to the Google Groups "gamsworld" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+...@googlegroups.com.
To post to this group, send email to gams...@googlegroups.com.
Visit this group at http://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.

Munier Elsherif

unread,
Sep 1, 2014, 10:14:26 PM9/1/14
to gams...@googlegroups.com
Claudio Delpino

The routine you posted seems to be giving some inputs to my problem. I have copied and pasted it in a Command Button sub routine and here is what I get
'gams' is not recognized as an internal or external command, operable program or batch file

C;|User\Munier\Documents\gamsdir\projdir>

Does this mean I should specify the location of the file I want to run on GAMS

Thank You for your help

Claudio Delpino

unread,
Sep 2, 2014, 3:34:59 PM9/2/14
to gams...@googlegroups.com
Munier: It would appear to me you have a path problem, where you don't have the gams executable in your windows path. 

- Try to call gams from the command prompt (win+R, run "cmd" without quotes, http://smallbusiness.chron.com/open-terminal-session-windows-7-56627.html). And write the command "gams" (without quotes again). You should get something along the lines of what I attached. If this happens correctly, then it's probably a VBA problem, look in VBA forums for this type of error when calling external applications. 

- If windows doesn't recognize gams as an executable (you'll get the same error you got in VBA), then check your PATH variable to see if the gams directory is included. This you do by writing "path" without quotes just like you wrote gams. 

If its not there, you can easily add the gams executable to your path in several ways ( http://stackoverflow.com/questions/9546324/adding-directory-to-path-environment-variable-in-windows  for example ) 

Check out my output for these commands in my attachment. 

Good Luck !!
Claudio
commands.png
Message has been deleted

Munier Elsherif

unread,
Sep 4, 2014, 7:00:36 AM9/4/14
to gams...@googlegroups.com
Now, after fixing the path issues I get a message that says missing input file name, and I mostly believe that it is the name of the file I want to run. Do you have any suggestion on how I could run the file with out having that command prompt (C:windows\system32\cmd.exe) window in the background?


I have tried several VBA forums to call the file from my VBA command button, and none of them seems to be fitting into the routine you've shared with me

I want to know how I can allocate the routine to my" gamsdir\projdir" so that it will run the model automatically  
Thank you!


On Wednesday, 3 September 2014 17:49:58 UTC+8, Munier Elsherif wrote:
Claudio,

I did call gams from command prompt without quotes and the same error popped up: saying my windows doesn't recognized  'gams' as an internal or external command, operable program or batch file. I did write path and gams is not there. I have attached my finding.

Can You please describe the steps of adding the gams executable to my path,  in step by step form so that I can follow. The link was not really helpful

Thank you

Munier Elsherif

unread,
Sep 4, 2014, 11:39:26 AM9/4/14
to gams...@googlegroups.com
It is done thank you again
Reply all
Reply to author
Forward
0 new messages