Results 1 to 3 of 3
  1. #1
    Lounger
    Join Date
    Mar 2002
    Location
    Cincinnati
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts

    AppActivate (2kSR1)

    Based on John Walkenbach's book, I have written the following code to fire up the Character Map application from inside Excel:

    Sub RunCharMap()
    Dim sProgram As String
    Dim iMsgResponse As Integer
    sProgram = "Charmap.exe"
    On Error Resume Next
    AppActivate ("Character Map") 'attempts to activate already running program
    If Err <> 0 Then 'was not running
    Err = 0 'reset the error flag
    iTaskID = Shell(sProgram, 1)
    If Err <> 0 Then
    iMsgResponse = MsgBox("Cannot Start " & sProgram, vbCritical, "Error")
    End If
    End If
    End Sub

    If I execute this program from the code page, it works great. But when I attach the macro to a button, it never finds existing copies of the application and keeps firing off new copies each time the button is clicked. How can I make this logic work through the use of a toolbar button?

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: AppActivate (2kSR1)

    I have a Word template I use to publish an HTML page and display it in a browser window. When I republish, I activate the existing browser window and use SendKeys to refresh the display. Not the most elegant programming, but it works.

    When I first launch the window, I store the TaskID as a custom document property. In the future, if that task exists, I activate it by TaskID rather than launching a new window. Since you probably want your code to be workbook-independent, you can store the TaskID in a text file or the registry, or maybe someplace more convenient. Hope this helps.

  3. #3
    3 Star Lounger
    Join Date
    Jun 2001
    Location
    Maidstone, Kent, England
    Posts
    398
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: AppActivate (2kSR1)

    I have just tried your code using E2K/W2K and it works as it should without creating duplicates!

    Not much help to you, but at least shows the problem is not the code <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •