Office.DocumentProperty type mismatch RRS feed

  • Question

  • Code is running in Access VBS. Office16 and Excel16 libraries are referenced. I have a Workbook object. This code is failing with a Type Mismatch:

    Dim p As DocumentProperty
    ' also tried
    ' Dim p As Office.DocumentProperty

    For Each p In wkbk.CustomDocumentProperties ' producing Type Mismatch

    I have looked at wkbk.CustomDocumentProperties in Watch; it says the type of CustomDocumentProperties(1) is Variant\Object\DocumentProperty. Likewise, an immediate ? TypeName(wkbk.CustomDocumentProperties(1)) produces DocumentProperty. I have also looked in Object Browser and have not found any ambiguous DocumentProperty types. There only appears to be the one.

    This code works:

    Dim p As Object
    For Each p In wkbk.CustomDocumentProperties

    Thanks in advance for any ideas why this Type Match error would be happening when the types appear to be the same by every way I can see to tell.

    • Edited by Dick Watson Tuesday, October 16, 2018 12:15 AM
    Monday, October 15, 2018 6:40 PM

All replies

  • Try

    Dim p As Excel.DocumentProperty

    to specify explicitly that you are using an Excel object.

    Regards, Hans Vogelaar (

    Monday, October 15, 2018 8:09 PM
  • When I read your reply, I though I had tried that somewhere along the way; I tried it again.

    Dim p As Excel.DocumentProperty

    won't compile: User-defined type not defined.

    Monday, October 15, 2018 9:07 PM
  • You're correct, that doesn't work. It's weird, using

    Dim p As DocumentProperty

    does work within Excel itself. I can't explain why it doesn't work when automating Excel from Access.

    Regards, Hans Vogelaar (

    Monday, October 15, 2018 10:01 PM