I'm trying to get an SQL window open in SQL Server Management Studio to display the SQL statement used (This is to allow people to modify the statement directly)
I don't wish to run the statement, I can do that already.
I can start a new process easily enough: (current code)
Public Sub ShowSQL(strSQL As String)
Dim TempSQL As String
Dim FileNum As Long
strSQL = Replace(strSQL, ",", "," & vbCrLf)
TempSQL = Get_Temp_File_Name
FileNum = FreeFile()
Open TempSQL For Output As #FileNum
Print #FileNum, strSQL
Close #FileNum
Shell "ssms " & TempSQL
End Sub
but I don't know how to tell if SSMS is already open.
For Excel, I know I can use GetObject(, "Excel.Application")
- what's the equivalent for SSMS?
(from a previous question, Shell "explorer " & TempSQL1
opens the file in the current instance, but fails if there is no SSMS instance open)