Getting current solidworks window, not a new window

I am having problems getting the current solidworks window when multiple versions of SolidWorks is open. I want to get an instance of swApp from the currently active 2017 SolidWorks window.

<p>SldWorks swApp = (SldWorks)Activator.CreateInstance(Type.GetTypeFromProgID("SolidWorks.Application"));</p>

or specifically I want 2017 SolidWorks

<p><span style="color: rgba(0, 0, 0, 0); font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px;">SldWorks swApp = (SldWorks)Activator.CreateInstance(Type.GetTypeFromProgID("SolidWorks.Application.25"));</span></p>

This works when only the 2017 version is opened. However, if 2012 was opened first, and the 2017 opened second, the above code creates a new window of SolidWorks 2017 instead of grabbing the current one.

Is it possible to be able to select which version and stop from making new windows?

SolidworksApi macros