question

Raashid Mohammed avatar image
1 Like"
Raashid Mohammed asked Phil BoBo edited

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

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

FlexSim 17.0.0
excel interface
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

1 Answer

·
Phil BoBo avatar image
3 Likes"
Phil BoBo answered Phil BoBo edited

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.

· 4
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Raashid Mohammed avatar image Raashid Mohammed commented ·

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 0 ·
Phil BoBo avatar image Phil BoBo ♦♦ Raashid Mohammed commented ·

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
1 Like 1 ·
Raashid Mohammed avatar image Raashid Mohammed Phil BoBo ♦♦ commented ·

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 0 ·
f.png (121.8 KiB)
Show more comments

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.