Results 1 to 14 of 14
  1. #1
    Star Lounger
    Join Date
    Jun 2004
    Location
    Gtr London, England
    Posts
    90
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Opening a document from Windows Explorer !! (Office 2003)

    Can anyone help please?

    I have a template which is held in the StartUp folder, the template, when loading Word, creates a toolbar and stores generic code which is used for other templates. If I open Word everything works the way it should but if I open a document through Windows Explorer without Word being opened I receive an error together with the toolbar not being created.

    The first message reads "The command cannot be performed as a dialog box is open. Click OK, and then close open dialog boxes to continue."

    The second message reads "This command is not available as no document is open".

    I am unsure why the first error is happening as I am not aware that I am opening a dialog box ... the code is just creating a toolbar, which is being called from "AutoExec".

    The second message I can only think relates to the blank document that is created when a user opens Word but is not created when a user opens a document from Windows Explorer.

    Has anyone come across this problem before and if so have you solved it. Have to just mention that I am not in a position where I can store code in Normal.dot due to other applications that require a clean Normal.dot.

    Many thanks for your help in advance
    Jack

  2. #2
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Opening a document from Windows Explorer !! (Office 2003)

    It would be nice to know what your code is doing when it generates this error. I have cured something similar in the past by checking for Application.Documents.Count = 0 and taking different action when there is no ActiveDocument.

    StuartR

  3. #3
    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: Opening a document from Windows Explorer !! (O

    I knew I'd seen that error message before. The context seems quite different, but you could try this thread and see if it helps at all.

  4. #4
    4 Star Lounger
    Join Date
    Dec 2003
    Location
    Zoetermeer, Zuid-Holland, Netherlands
    Posts
    559
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Opening a document from Windows Explorer !! (Office 2003)

    Maybe this is a timing problem. The AutoExec in a global template is fired when Word starts. If you start Word first and then open a document, Word already finished executing the code in AutoExec, so the toolbar already exists and there also is "document1" opened by default.
    When you double click on a doc in Explorer without Word already open, this is not the case. So maybe Word tries to open the doc you double clicked on before the code in AutoExec is fully executed and no default doc is opened? If that's the case, maybe a short delay in AutoExec before the toolbar is created would do the trick.

  5. #5
    Star Lounger
    Join Date
    Jun 2004
    Location
    Gtr London, England
    Posts
    90
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Opening a document from Windows Explorer !! (Office 2003)

    (Edited by HansV to make URL clickable - see <!help=19>Help 19<!/help>)

    Thanks for the reply Jan. I've done a search on the internet and have found a Microsoft article that descibes the error (link below):

    http://support.microsoft.com/default.aspx?...kb;en-us;827732

    Unfortunately Microsoft does not come up with a solution (apart from remove the template from StartUp) !! Do you know if there is an alternative to AutoExec - at the moment I am grasping at straws.

    Many thanks
    Jackie

  6. #6
    Star Lounger
    Join Date
    Jun 2004
    Location
    Gtr London, England
    Posts
    90
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Opening a document from Windows Explorer !! (Office 2003)

    Morning Stuart

    Would you mind taking a look at the last post on the above subject. It includes a link to a Microsoft article which identifies the error and offers a solution !! If you can think of another way around the error it would be greatly appreciated.

    Thanks
    Jackie

  7. #7
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Opening a document from Windows Explorer !! (Office 2003)

    Here are two possible approaches you might want to try.
    1. <LI>In AutoExec use Application.Ontime to call your code after a short delay. This will be very simple to code but it will take trial and error to work out whether the delay should be 1 second or 8 seconds, and if you have lots of people using your code then it will generate lots of support activity.
      <LI>Move the code from AutoExec to a different application event<UL><LI>Create a global flag to show whether the code has successfully run yet
      <LI>In AutoExec create an Event Handler for the DocumentOpen and DocumentNew events
      <LI>In the events check the global flag, if it is set then exit
      <LI>Check that Application.Documents.Count is at least one, otherwise exit
      <LI>Create your toolbars etc.
      <LI>Set the global flag
    [/list]StuartR

  8. #8
    Star Lounger
    Join Date
    Jun 2004
    Location
    Gtr London, England
    Posts
    90
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Opening a document from Windows Explorer !! (Office 2003)

    Edited by StuartR to make link active, see <!help=19>Help 19<!/help>

    Hi Stuart

    You will be pleased to know the problem is now solved (and it didn't involve the Microsoft fix !!). To enable a template to reside in StartUp that runs when a user opens a document through Windows Explorer or through loading Word you need to user the WithEvents function. See link below:

    http://msdn.microsoft.com/library/default....ngAppEvents.asp

    AutoExec then calls "Register_Event_Handler" (see link). Within the class put:

    Private Sub appWord_DocumentChange()

    If (Application.Documents.Count > 0) Then "run function required"

    End Sub

    This will then work on opening documents in Word and opening documents through Windows Explorer.

    Regards
    Jackie

  9. #9
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Opening a document from Windows Explorer !! (Office 2003)

    The DocumentChange event will fire every time the user switches between Word documents. Do you really want your code to run this often?

    You may want to consider using DocumentOpen and DocumentNew instead, or using a global flag to ensure your code only does its stuff once.

    StuartR

  10. #10
    4 Star Lounger
    Join Date
    Dec 2003
    Location
    Zoetermeer, Zuid-Holland, Netherlands
    Posts
    559
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Opening a document from Windows Explorer !! (Office 2003)

    Jackie,

    Do not use the DocumentChange event in Word2002/2003 for that purpose!
    I did try it and it's not reliable. See my <post#=360433>post 360433</post#>.
    Use the NewDocument and DocumentOpen events instead, as Stuart suggested.

  11. #11
    Star Lounger
    Join Date
    Jun 2004
    Location
    Gtr London, England
    Posts
    90
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Opening a document from Windows Explorer !! (Office 2003)

    Morning Jan

    I initially used the NewDocument and DocumentOpen events. If I opened a document through Windows Explorer the toolbar (stored in StartUp) loaded without any problems but when opening Word the toolbar did not run. I then used the DocumentChange event and put in place an "if statement" that identifies whether the toolbar has been loaded, if not loaded then load, if loaded then don't do anything.

    My thinking behind NewDocument not running is that when Word loads, it goes through StartUp on loading then creates Document 1, hence the event does not run and the toolbar does not get created. I did put Message Boxes in both NewDocument and DocumentOpen and in every case NewDocument event did not run on loading Word.

    The only solution I could think of was the DocumentChange event which works for both opening documents from Windows Explorer and opening Word. If you can think of another solution (as Stuart has stated the code is running everytime I open documents etc) I would be very happy to give it a try.

    Many thanks
    Jackie

  12. #12
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Opening a document from Windows Explorer !! (Office 2003)

    Since you have 'put in place an "if statement" that identifies whether the toolbar has been loaded, if not loaded then load, if loaded then don't do anything' the overhead of putting your code in the DocumentChange event should be pretty small. If it's working and you're happy with it then I suggest leaving it alone.

    StuartR

  13. #13
    4 Star Lounger
    Join Date
    Dec 2003
    Location
    Zoetermeer, Zuid-Holland, Netherlands
    Posts
    559
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Opening a document from Windows Explorer !! (Office 2003)

    I agree with Stuart; if it works for you, then stick with DocumentChange.

  14. #14
    Star Lounger
    Join Date
    Jun 2004
    Location
    Gtr London, England
    Posts
    90
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Opening a document from Windows Explorer !! (Office 2003)

    Phew ... you guys really worried me !!

    Many thank for your help though.
    Have a good weekend
    Jack

Posting Permissions

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