Results 1 to 5 of 5
  1. #1
    New Lounger
    Join Date
    Sep 2002
    Location
    Bend, Oregon, USA
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Word / IE Automation trapping Save Changes prompt (VBA Word 97/2000)

    I am running Word document with Macro inside IE 5+ that allows user to modify the document and post the it to the webserver with the Save icon. I catch the Save and SaveAs command events, rename and save the document locally, post the document to the web server, then attempt to navigate the user back to the web application interface with my IE object. All works fine, except IE or Word identifies that the original document (remote document) has changed and prompts the user to save, which invokes the Word SaveAs dialog when user clicks yes, or navigates correctly when user clicks No.

    I want to trap, disable or bypass the "This document has been modified. Do you want to save changes?" dialog, but have not been successful.

    Application Objects:

    oWordApp As Word.Application
    mIe As InternetExplorer
    oWordApp = GetObject (, "Word.Application")
    mIe = ActiveDocument.Container ' Verified as TopLevelContainer -GetOjbect fails

    Attempts in VBA with Word Object:

    ActiveDocument.saved = true
    ThisDocuments.saved = true
    Application.DisplayAlerts =wdAlertsNone
    oWordApp.ActiveDocument.Close SaveChanges = False ' RT error '4605' document is in another application
    Private WithEvents oWordApp As Word.Application
    Private Sub oWordApp_DocumentChange()

    Attempts in VBA with IE Object:

    mIe.Silent = True
    mIe.ExecWB OLECMDID_ALLOWUILESSSAVEAS, OLECMDEXEOPT_DONTPROMPTUSER
    mIe.ExecWB OLECMDID_SAVEAS, OLECMDEXECOPT_DONTPROMPTUSER


    note: If I Show wdDialogFileSvaeAs immediately after my mIe.navigate statement, I avoid the Save Changes prompt, but am still stuck with SaveAs dialog that I don't want or need.

    There appears to be a question of application control of the document when it comes to OLE / Automation on ActiveX Documents between Container (Client) and Application (Automation Server), in this case IE and Word. I cannot close the document with Word object ( RT error '4605' document is in another application ) and none of the Word object properties have any effect. IE shouldn't care one way or another if a remote document has been modified.

    Im spent and not sure where to go. Anyone care to give this a shot? oWord.ActiveDocument.Hyperlinks to navigate maybe?

    thanks

    bl

  2. #2
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Word / IE Automation trapping Save Changes prompt (VBA Word 97/2000)

    Hi,
    I don't know if this will help as Word is not my strong point, but can you use the execute method of the dialog rather than the show method?
    Regards,
    Rory

    Microsoft MVP - Excel

  3. #3
    New Lounger
    Join Date
    Sep 2002
    Location
    Bend, Oregon, USA
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word / IE Automation trapping Save Changes prompt (VBA Word 97/2000)

    rory,

    ya, I tried .Execute with .Show / .Display remarked and it through the original SaveChanges dialog. I wish I could execute a Cancel event on the SaveAs dialog. Even if the SaveAs popped up for a second, then disappeared, it would not require user interaction. I just want it to be as seemless as possible.

    thanks

  4. #4
    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: Word / IE Automation trapping Save Changes prompt (VBA Word 97/2000)

    Yes, security constraints prohibit use of GetObject from inside IE, darn it.

    How are you using the built-in SaveAs dialog? In <!post=Post #165023,165023>Post #165023<!/post>, Gary Frieder posted a trick using the .Display method to "flash" a dialog for a millisecond. If you do that, perhaps there is a way to do something useful at that point?

    How about doing it completely differently... and creating a new document in the browser? If you look for a post by me discussing how to use VBScript to launch a new document from a template on an intranet. I've coded doing this so it opens in Word (e.g., <!post=Post #130411,130411>Post #130411<!/post>), but don't really know exactly how you would do it in IE. Perhaps make a local copy of the document first and then open it with IE from the C drive? If you can just get to Word.Documents.Add Template:="MyDoc.doc" maybe it will all happen automatically??

    Good luck. Interesting hobbies, by the way.

  5. #5
    New Lounger
    Join Date
    Sep 2002
    Location
    Bend, Oregon, USA
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word / IE Automation trapping Save Changes prompt (VBA Word 97/2000)

    jscher2000,

    I need to have the (technically challenged) user begin with my template document on the web server that contains the macro code to post it back to the server seemlessly when saved. Future edits of the user's modified doc also utilize the same macro code. Otherwise, I would definately do it differently.


    Yes, I am using the built-in SaveAs dialog, which is invoked with user response Yes to SaveChanges prompt. I think I will go with Gary's .Display timeout trick, as it does Flash for a second, executes and navigates. It's not 100% clean, but I think it is as close as I can get. If only I could trap the document_change event, I think I would have it. Oh well... It's surprising not to see much if any Web based VBA automation posts or documentation around the web. You would think everyone would be automating office apps via the net.

    thanks All, especially jscher2000 and Gary Frieder


    Resolution code snippet

    With mIe ' IExplorer Object
    .Silent = True
    .navigate ("http://URL/upload.asp?QuerySting")
    End With

    With oWordApp ' Word Object
    .Dialogs(wdDialogFileSummaryInfo).Title = "junk"
    .Dialogs(wdDialogFileSummaryInfo).Subject = "junk"
    .Dialogs(wdDialogFileSummaryInfo).Update
    .Dialgos(wdDialogFileSaveAs).Name = "junk.doc"
    .Dialogs(wdDialogFileSaveAs).Dispaly 1 ' Timeout Value
    .Dialogs(wdDialogFileSaveAs).Execute
    End With

    End Sub


    B L (happy lizard) <img src=/S/clapping.gif border=0 alt=clapping width=19 height=23>

Posting Permissions

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