Both the GetObject and CreateObject commands can be used to open Surfer via automation. The GetObject function uses an existing open instance of Surfer to run the script and the CreateObject function opens a new Surfer application window.
For example, if you want the script to open Surfer and perform actions, use CreateObject:
Dim SurferApp As Object Set SurferApp = CreateObject("Surfer.Application") SurferApp.Visible = True
If you want to open Surfer first, and then run the script and have the script use the instance of Surfer that is already open, use GetObject:
Dim SurferApp As Object Set SurferApp = GetObject(, "Surfer.Application") SurferApp.Visible = True
This is useful if you have multiple versions of Surfer installed on the computer and you want to run a script using a particular version, or if you want to perform some actions in Surfer first and then run the script and have the script apply the actions to the open file.
This can also be useful if you are using a concurrent use license and don't want to accidentally reserve two license seats (preventing others from using the software) by having more than 3 instances of Surfer opened at one time. The code below checks for an open instance of Surfer to use before opening a new one each time a script is run.
On Error Resume Next
Set SurferApplication = GetObject( ,"Surfer.Application")
If Err.Number <> 0 Then
Set SurferApplication = CreateObject("Surfer.Application")
On Error GoTo 0
Updated November 2021