Results 1 to 9 of 9
  1. #1
    3 Star Lounger rcbjr2's Avatar
    Join Date
    Jan 2001
    Location
    Matthews, NC
    Posts
    279
    Thanks
    6
    Thanked 1 Time in 1 Post

    VBA Object Error 'AutoNew' (Word 2000 SR3)

    I'm trying to pop up a MsgBox in a .DOT file that works with both AutoNew and AutoOpen (just in case someone opens the template). However, I keep getting an object error for AutoNew. Here's my code:

    Public Sub AutoOpen()

    ' Turn on field shading so user can view fields
    ActiveWindow.View.FieldShading = wdFieldShadingAlways

    ' Displays initial instructional message
    Dim ResultOpen

    MsgBox "INSTRUCTIONS: " _
    & vbCr & vbCr _
    + "If this document is not protected, click each data field " _
    + "and type in the requested data." _
    & vbCr & vbCr _
    + "If this document is protected, scroll through the data" _
    + "fields using TAB and SHIFT+TAB" _
    & vbCr _
    + "and type in the requested data." _
    & vbCr, vbExclamation

    End Sub
    Public Sub AutoNew()

    ' Turn on field shading so user can view fields
    ActiveWindow.View.FieldShading = wdFieldShadingAlways

    ' Displays initial instructional message
    Dim ResultNew

    MsgBox "INSTRUCTIONS: " _
    & vbCr & vbCr _
    + "If this document is not protected, click each data field " _
    + "and type in the requested data." _
    & vbCr & vbCr _
    + "If this document is protected, scroll through the data" _
    + "fields using TAB and SHIFT+TAB" _
    & vbCr _
    + "and type in the requested data." _
    & vbCr, vbExclamation

    End Sub

    Can someone tell me what I'm doing wrong?

    Thx.

    -Rich Belthoff

  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: VBA Object Error 'AutoNew' (Word 2000 SR3)

    Rich, when you get the error, if you click Debug, which line is highlighted?

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

    Re: VBA Object Error 'AutoNew' (Word 2000 SR3)

    This would be much more maintainable if you created a single routine that did the work and called it from both AutoOpen and AutoNew.
    You could debug the MySetup routine once and call it from both places

    Sub AutoOpen
    MySetup
    End Sub

    Sub AutoNew
    MySetup
    End Sub

    Sub MySetup
    <font color=448800>' Put all of your code here</font color=448800>
    End Sub

    StuartR

  4. #4
    3 Star Lounger rcbjr2's Avatar
    Join Date
    Jan 2001
    Location
    Matthews, NC
    Posts
    279
    Thanks
    6
    Thanked 1 Time in 1 Post

    Re: VBA Object Error 'AutoNew' (Word 2000 SR3)

    It appears that the fieldshading line is causing the trouble. However, it works with AutoOpen, but not AutoNew. Is it something about the file not being named yet?

    Thx.

    -Rich Belthoff

  5. #5
    3 Star Lounger rcbjr2's Avatar
    Join Date
    Jan 2001
    Location
    Matthews, NC
    Posts
    279
    Thanks
    6
    Thanked 1 Time in 1 Post

    Re: VBA Object Error 'AutoNew' (Word 2000 SR3)

    Thanks. That's a good idea. I'll try that.

    -Rich

  6. #6
    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: VBA Object Error 'AutoNew' (Word 2000 SR3)

    I can't replicate the error in Word 2000 SP2. I created a new template with this code:

    Sub autonew()
    ActiveWindow.View.FieldShading = wdFieldShadingAlways
    MsgBox "Hi there"
    End Sub

    And it worked whether Word was already running or not (I just double clicked the template on the desktop).

    I wonder if the error is a side effect of the new field code security feature? Can you tell us exactly what the error message is?

  7. #7
    Lounger
    Join Date
    Dec 2002
    Location
    Hull, Yorkshire, England
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA Object Error 'AutoNew' (Word 2000 SR3)

    Hi rich,

    Are your AutoOpen and AutoNew macros inside the ThisDocument module of your template's project? I found (using Wd 2000 SR1) that if I tried to access the ActiveWindow object in an AutoNew macro inside the ThisDocument module I would get an

  8. #8
    3 Star Lounger rcbjr2's Avatar
    Join Date
    Jan 2001
    Location
    Matthews, NC
    Posts
    279
    Thanks
    6
    Thanked 1 Time in 1 Post

    Re: VBA Object Error 'AutoNew' (Word 2000 SR3)

    Thanks for the reply. See Ed Craig's message. I was getting the error he mentioned, but when I moved the code from Project to the NewMacros module, I quit getting the error!

    Thx.

    -Rich Belthoff

  9. #9
    3 Star Lounger rcbjr2's Avatar
    Join Date
    Jan 2001
    Location
    Matthews, NC
    Posts
    279
    Thanks
    6
    Thanked 1 Time in 1 Post

    Re: VBA Object Error 'AutoNew' (Word 2000 SR3)

    Fantastic, Ed! That's the problem. I moved the code out of Project to the NewMacros module and it works fine!!

    Thx.

    -Rich Belthoff

Posting Permissions

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