Results 1 to 4 of 4
  1. #1
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Detect program? (Word97/XL97/WinNT4)

    Is there any way to write VBA code that can detect which program a file has been opened in?

    The reason I ask is that we have recently had a spate of incidents where XL spreadsheets have been ruined by someone opening them in Word and saving them, so I'd like to put a document open sub in that can detect if it's been opened in Word and put up a message to that effect.

    Any help gratefully appreciated!
    Beryl M


  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Detect program? (Word97/XL97/WinNT4)

    I created an Excel workbook with a simple MsgBox instruction in the Workbook_Open event procedure. When I opened the workbook in Word, the Workbook_Open event procedure was *not* executed, so that seems useless. I did get the dialog displayed below. And since I have "Confirm conversion at Open" ticked in the General tab of Tools | Options..., the dialog was preceded by another one. So I got two warnings, at each of which opening of the file could be canceled.

  3. #3
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Detect program? (Word97/XL97/WinNT4)

    Hi, Hans, thanks for trying - that was the sort of thing I was coming up against, too! However, I have thought of a way round it - we have standard normal.dots here (although this could be put in a template in the startup directory for those who don't, of course) so I wrote this little snippet that intercepts the FileSave and FileClose in Word:

    Sub Filesave()
    If Right(ActiveDocument.name, 4) = ".xls" Then
    MsgBox "This is an Excel workbook," + Chr(10) + "not a Word document!" + Chr(10) + Chr(10) + _
    "Please close and reopen" + Chr(10) + "in Excel.", vbCritical
    Else
    Dialogs(wdDialogFileSaveAs).Show
    End If
    End Sub

    Sub FileClose()
    If Right(ActiveDocument.name, 4) = ".xls" Then
    MsgBox "This is an Excel workbook," + Chr(10) + "not a Word document!" + Chr(10) + Chr(10) + _
    "Please close and reopen" + Chr(10) + "in Excel.", vbCritical
    Else
    ActiveDocument.Close
    End If
    End Sub

    This works perfectly in that it doesn't affect Word documents at all but intercepts all the standard ways of saving and closing EXCEPT - it doesn't come up if the user presses Ctrl-F4 or clicks the X in top right to close the document, then just says 'Yes' when asked if they want to save.

    Do you happen to know the intercept command for those operations? It doesn't seem to be FileCloseDefault ...
    Beryl M


  4. #4
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Detect program? (Word97/XL97/WinNT4)

    Don't worry, I've found it! I actually managed to find some Search terms that found the answer I wanted!! <img src=/S/thumbup.gif border=0 alt=thumbup width=15 height=15>

    It's here!

    Many thanks!
    Beryl M


Posting Permissions

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