TALtech Logo
search
Products Support Resources Free Software
   TALtech Home:  Support:  WinWedge Support:  DDE and the WinWedge: WinWedge DDE Examples:



Launching the WinWedge from Excel

The following VBA subroutine executes the Software Wedge and passes it the name of a WinWedge configuration file (MyConfig.SW3) on the command line. This causes WinWedge to automatically load the specified configuration file and then activate itself in NORMAL mode.

Public Const MyPort$ = "COM1"

' change port if necessary

Sub RunWedge()

' Set up an error trap
On Error Goto ErrorHandler

' try to activate the Wedge Window
' if Wedge is not running or activated this line will generate an error

AppActivate "Software Wedge - " + MyPort$

''''''''''''''''''''''''''''''''''''''''''''''
' NOTE: For WinWedge 3.0 Std use:

' AppActivate "WinWedge - " + MyPort$
''''''''''''''''''''''''''''''''''''''''''''''


' remove error trap
On Error Goto 0

' set the focus back to excel & exit
AppActivate Application.Caption
Exit Sub

ErrorHandler:

' If we get here the wedge is not running, so launch it:
RetVal = Shell("C:\WINWEDGE\WINWEDGE.EXE _
C:\WINWEDGE\MyConfig.SW3")

' give wedge time to load ~ 2 secs, then resume.
Application.Wait Now + TimeValue("00:00:02")
Resume Next

End Sub


Note:
If you name an Excel subroutine "Auto_Open()", Excel will automatically run the routine whenever the spreadsheet that contains it is initially opened. The Auto_Open subroutine is an excellent place to launch the Wedge (as well as do any other initialization functions that you might require). If you re-name the above subroutine to "Auto_Open()" then you can save yourself the step of having to manually run the above subroutine.

Similar to the Auto_Open subroutine, Excel also supports an Auto_Close subroutine that runs automatically when you close your spreadsheet. This might be a good place to tell the Wedge to quit and unload itself from memory as in the following example.

Sub Auto_Close()

' this sub runs when you close
' the sheet

On Error Resume Next
chan = DDEInitiate("WinWedge", MyPort$)
DDEExecute chan, "[Appexit]"

DDETerminate chan

' ignore errors and try to launch
' WinWedge
' open a dde link with the wedge
' tell wedge to quit
'Terminate the channel

End Sub

Back to Top

TALtech Home  |  Products  |  Resources  |  Free Software  |  Support  |  Buy Now  |  Register Your Products  | 
Site Map  |  Contact TALtech  |  News