Consulting

Results 1 to 4 of 4

Thread: VBA Compiler broken?

  1. #1
    VBAX Master
    Joined
    Feb 2011
    Posts
    1,480
    Location

    VBA Compiler broken?

    I've tested this in Office 365 and 2016... is this is some kind of fundamental change to the compiler, or have I just missed this bug all these years?
    Sub Test1
    Dim p As Paragraph
    
    
    Set p = Selection.Paragraphs.First
    Test2 p.Range
    End Sub Sub Test2(p as Paragraph) Debug.Print p.Range.Text End Sub
    Why does that only provoke a run-time error of type mismatch? Shouldn't it provoke a compile error?
    Last edited by xld; 07-29-2019 at 06:38 AM. Reason: Formatting
    _______________________________________________
    Please don't cross-post without providing links to your cross-posts. We answer questions for free. Please don't waste the time of the people helping you.
    For cross-posting etiquette, please read: http://www.excelguru.ca/content.php?184

    - Frosty

  2. #2
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,046
    Location
    Jason,

    Tested your code in Word 2013, 2010, 2007 and 2003 with same result. I suppose it has just been missed.
    Greg

    Visit my website: http://gregmaxey.com

  3. #3
    VBAX Master
    Joined
    Feb 2011
    Posts
    1,480
    Location
    Thanks, Greg... so I'm just... crazy. I can't believe I've never noticed that. I rely on the compiler to catch my mistakes all the time.

    It catches if I try to pass a footnote object when the routine is expecting a document object... seems strange to mess up on this.
    _______________________________________________
    Please don't cross-post without providing links to your cross-posts. We answer questions for free. Please don't waste the time of the people helping you.
    For cross-posting etiquette, please read: http://www.excelguru.ca/content.php?184

    - Frosty

  4. #4
    VBAX Wizard
    Joined
    Apr 2007
    Posts
    6,661
    Location
    A guess -- Word seems to have a complex object model with (IMO) some 'overlap' in things like Selection, Range, etc. returnng even more 'lower level' objects

    P and P.range are objects and pass the the 'compile time' checks since Test2 is expecting an object address, and it doesn't fail until R/T

    A non-object variable is caught at compile time

    As I said, this is a guess and as we all know "Mysterious Are the Ways of MS Word"


    Capture.JPG
    Paul

    ------------------------------------------------------------------------------------------------------------------------
    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s)
    (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Posting Permissions

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