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:

  1. 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:

  1. "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:

  1. Private Sub CommandButton2_Click()
  2. Dim myPath As String
  3. Dim Simpath As String
  4. myPath = Application.ActiveWorkbook.Path
  5. Simpath = """" & myPath & "\..\" & "program\flexsim.exe" & """ """ & myPath & "\test.fsm" & """"
  6. Shell Simpath, vbNormalFocus
  7. 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.