Results 1 to 6 of 6
  1. #1
    2 Star Lounger
    Join Date
    Dec 2007
    Posts
    179
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Folder type not recognized in Word docs and dots

    Hi all,

    I have a really weird bug with Word VBA API access.

    In short, in certain Word document and template files I am finding that the VBA IDE does not recognize the Folder type, and code that accesses that type does not run.

    Thus, when I type something like:
    Dim fldr as ...

    The drop down list of types that appears does not include Folder (and also not Folders).

    Longer version: I had developed some code in a Word 2003 DOT file to use as an add-in. The code involved processing folders. Once I had verified that the code correctly worked, I then decided to merge all the code and its forms into an existing template. Only then I discovered that some of the code was not recognized as VBA in the 'new' template file. The VBA interpreter flagged that the 'Folder' type was not recognized. Weird… Then I checked if the same thing occurred in Word 2007. Yes, it does. Then I checked if the same thing occurred also in other docs and template files. Yes it does - and even in the Normal template. So now it looks like that is the norm and that I was just 'lucky' that until now, in the template I had been using to develop the code, I could access the Folder type.

    I suppose a work-around would be that I could just declare as variants all the objects that I need as 'Folder' type. But I didn’t try this yet.

    Anybody encountered something like this, that part of VBA is not accessible?

    TIA

    -avraham

  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
    If you were previously working with the FileSystemObject, you may need to add a reference to a scripting library. Check Tools > References on the working template to get the exact name.

  3. #3
    2 Star Lounger
    Join Date
    Dec 2007
    Posts
    179
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Oh boy ... you are right. But this was the last thing I expected. i.e., that each document preserves its own Reference settings. I assumed that all the settings accessed up there on the toolbar are *global* settings. They are not.

    So now I ensured that MS Scripting Runtime is selected for the document, and now everything works.

    Another thing: So does this mean that I also earn a bonus: when I send the template to my client I won't need to tell her to add a reference, since the document preserves its own set of references?

    Thanks,
    avraham

  4. #4
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts
    Yes and no. You won't need to tell the client to add the reference if you have set it in the template but...

    References point to a specific version. If your client has the same version or later installed on their machine then everything should work fine. However, if they have an earlier version of the same reference installed then the reference link may be broken. Developers get around this issue by using 'Late Binding' which you could do a search for if you wanted to make your life more complicated.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  5. #5
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts
    This post has an example of late binding to one of the scripting libraries: Remove reply indenting from HTML message. It's much easier during development to use the reference because it supplies autocompletion for objects, properties, and methods. You can convert to late binding after everything is working.

  6. #6
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts
    Strictly relating to the Microsoft Scripting Runtime (scrrun.dll) it's probably safe to just use early binding - I've used this in every version of Word through Word 2010 without any problems. Can't say for sure without researching further, but I think this particular library hasn't been changed in years. (Can't vouch for 64-bit.)

    Gary

Posting Permissions

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