Launch Flexsim.exe and Model from Excel VBA without installing flexsim software

Launch Flexsim.exe and Model from Excel VBA without installing flexsim software

raashid_mohammed1
Not applicable
537 Views
5 Replies
Message 1 of 6

Launch Flexsim.exe and Model from Excel VBA without installing flexsim software

raashid_mohammed1
Not applicable

[ FlexSim 17.0.0 ]

Hi

1. I copied the entire Flexsim 2017 folder to Desktop

2. I added start macros excel file inside Flexsim 2017 folder

3. I added Model folder with script.txt and test.fsm model inside Flexsim 2017 folder

4. I wrote VBA code in start excel file

Private Sub CommandButton2_Click()

Dim myPath As String

Dim folderPath As String

Dim Simpath As String

Dim Modelpath As String

folderPath = CurDir()

myPath = Application.ActiveWorkbook.FullName

Simpath = folderPath & "\" & "program\flexsim.exe" Modelpath = folderPath & "\Model\test.fsm"

Shell Simpath, vbNormalFocus

Shell Modelpath, vbNormalFocus

End Sub

when I run the code It opens the flexsim.exe file but does not open the test model and run it

Please help

Thanks

Accepted solutions (1)
538 Views
5 Replies
Replies (5)
Message 2 of 6

philboboADSK
Autodesk
Autodesk
Accepted solution

This line has a syntax error in VBA:

Simpath = folderPath & "\" & "program\flexsim.exe" Modelpath = folderPath & "\Model\test.fsm"

I guess this was supposed to be two different lines? You are trying to execute flexsim and then execute a model file as two separate Shell commands. You need to execute flexsim and pass the model file as a parameter into a single Shell command.

To open the model, you specify a path to it after the path to the flexsim.exe executable, such that your Simpath string looks something like this:

"C:\Users\USERNAME\Desktop\FlexSim 2017\program\flexsim.exe" "C:\Users\USERNAME\Desktop\FlexSim 2017\Model\test.fsm"

Here is VBA code that will open FlexSim with the specified model based on the structure you set up on your desktop:

Private Sub CommandButton2_Click()
Dim myPath As String
Dim Simpath As String
myPath = Application.ActiveWorkbook.Path
Simpath = """" & myPath & "\..\" & "program\flexsim.exe" & """ """ & myPath & "\test.fsm" & """"
Shell Simpath, vbNormalFocus
End Sub

Ben's answer in Automatically Configure and Run a FlexSim Model has additional information regarding other command line parameters that you can pass FlexSim. The commands that you can enter through a command prompt can also be entered as a concatenated string to the Shell command in VBA.



Phil BoBo
Sr. Manager, Software Development
Message 3 of 6

raashid_mohammed1
Not applicable

HI

It says file not found

I copied and pasted the VBA code you sent it did not work

I change the path to make sure it goes to the right model location

Private Sub CommandButton2_Click()
Dim myPath As String
Dim Simpath As String
myPath = Application.ActiveWorkbook.Path
Simpath = """" & myPath & "\..\" & "program\flexsim.exe" & """ """ & myPath & "Model\test.fsm" & """"
Shell Simpath, vbNormalFocus
End Sub

0 Likes
Message 4 of 6

philboboADSK
Autodesk
Autodesk

If your Excel file isn't in the Model directory, you need to take the .. out of the path to flexsim.exe in addition to adding \Model to the path to the model.

Private Sub CommandButton2_Click()
Dim myPath As String
Dim Simpath As String
myPath = Application.ActiveWorkbook.Path
Simpath = """" & myPath & "\program\flexsim.exe" & """ """ & myPath & "\Model\test.fsm" & """"
Shell Simpath, vbNormalFocus
End Sub


Phil BoBo
Sr. Manager, Software Development
Message 5 of 6

raashid_mohammed1
Not applicable

5686-f.png

HI

Thanks it works now

Looks like i have to install the flexsim software to run the models on my computer

It works for Flexsim 2016 update 2 but not for Flexsim 2017

it gives me licensing error

I would like to run the model without installing the software

FYI..the user is admin for his computer

Thanks

0 Likes
Message 6 of 6

philboboADSK
Autodesk
Autodesk

In order to open FlexSim, the license service needs to be installed. The installer installs it. FlexSim itself will also install it when you run FlexSim as an administrator.

Running a program as an administrator is different than just running a program while logged in with an admin user. You have to actually explicitly tell it to run as an administrator by right-clicking the program and selecting "Run as administrator."

You can also right-click a shortcut to go to its Properties and set "Run as administrator" in the Advanced Properties of the shortcut.

You might also be able to install the licensing service directly from the DLL in FlexSim's install directory. The file FNP_Act_Installer.dll has an exported function called fnpActSvcInstallForMSI() which you might be able to call directly from VBA. Figuring out how to do that in Excel is beyond the scope of FlexSim technical support though. If you want to go that route, it is up to you to try to figure out how to do that.



Phil BoBo
Sr. Manager, Software Development
0 Likes