Consulting

Results 1 to 4 of 4

Thread: Abort opening a document in VBA

  1. #1

    Abort opening a document in VBA

    Hi,
    I've not posted here for several years, but I still remember the best experts are here on this forum. So here's my problem.

    I'm working on a program that processes all docx documents in a folder. I'm opening the documents one by one.
        Set WA = CreateObject("Word.Application")
        WA.Visible = True
        Set WD = WA.Documents.Open(FileName:=DocPath, ConfirmConversions:=False, ReadOnly:=True, NoEncodingDialog:=True)
    However, some of the documents are password protected. And here my program stops working, waiting for user interaction. I would like to automatically abort the document opening, if, for example, it's not successful for 10 seconds (e.g. proper password was not supplied). I was trying to set up a form timer, with interval of 10000, that would quit then recreate the word application:
    Private Sub Form_Timer()
        WA.Quit
        Set WA = CreateObject("Word.Application")
        WA.Visible = True
    End Sub
    But it never gets executed while the Word Application waits for the password.
    I thought maybe I could set the Word app/window to be non-modal, but I found nothing that made this possible.
    Any ideas how to crack this nut?

    Jimmy
    -------------------------------------------------
    The more details you give, the easier it is to understand your question. Don't save the effort, tell us twice rather than not at all. The amount of info you give strongly influences the quality of answer, and also how fast you get it.

  2. #2
    I've found another approach.
    http://wordmvp.com/FAQs/MacrosVBA/Ch...tectB4Open.htm
    Problem solved
    -------------------------------------------------
    The more details you give, the easier it is to understand your question. Don't save the effort, tell us twice rather than not at all. The amount of info you give strongly influences the quality of answer, and also how fast you get it.

  3. #3
    Thanks for paying it forward by sharing your solution.
    Boyd Trimmell aka HiTechCoach
    Microsoft Access MVP -2010-2015

    Programming: Nine different ways to do it right, a thousand ways to do it wrong.
    Binary--it's as easy as 1-10-11

  4. #4
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    For code that loops through a folder and its subfolders, plus generates a report of any files it couldn't process, see: http://www.eileenslounge.com/viewtop...=14499#p107602 and the modifications in http://www.eileenslounge.com/viewtop...=14499#p110877
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

Posting Permissions

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