Excel CustomDocumentProperties

Add-in Express™ Support Service
That's what is more important than anything else

Excel CustomDocumentProperties
Type Missmatch Excel CustomDocumentProperties 
Michael Kaden




Posts: 322
Joined: 2017-11-15
Hello,

I am trying to add custom properties to an Excel Workbook (Office 365 / Win 10)


            Dim BookNow As Excel.Workbook = alera.AddinModule.CurrentInstance.GetActiveWorkbook()

            BookNow.CustomDocumentProperties.Add("x", "W")

     


I get Error 13 "Type Missmatch"

ps I believe I have a syntax error and I read through the forum and a lot in the web but all examples there are in C# and automatic convertors to Vb.net do not point me to the error.

Please help, thank you.

kind regards

Michael
Posted 26 Aug, 2021 14:15:16 Top
Andrei Smolin


Add-in Express team


Posts: 17953
Joined: 2006-05-11
Hello Michael,

Error 13 "Type Mismatch" is a VBA error. Check if there's a VBA macro involved in your case.

Regards from Poland (CEST),

Andrei Smolin
Add-in Express Team Leader
Posted 26 Aug, 2021 15:21:37 Top
Michael Kaden




Posts: 322
Joined: 2017-11-15
Thank you very much Andrei for your prompt reply.

No, there is no VBA code or Macro in this workbook. Only VB.net.

I must apologize, I guess Error 13 comes from me using On Error Goto.... in all my code and I know it is an old, not recommended method from VB times. If Microsoft would finally get away from it, well then I will have to bit the bullet. For me it is the only way to easily identify each line where any error is raised. I have made a little program which automatically puts labels in front of each code line and then I can design my errorhandler giving me all err. Objects including err.Erl I always write all the error message in a Log file which my users can easily send to me. This saves a lot of time when the user is on the other side of this planet.

Although many have recommended to use Try ... Catch....Finally and i have tried it a lot, but never got the comfort of error handling as with the err Object.

So sorry for the confusion. I am really just looking for the correct syntax in VB.net Visual basic to make a new Excel workbook attribute, change it and erase it. I found so many suggestions in the internet, which unfortunately none of them worked.


thank you for your help

kind regards

Michael
Posted 26 Aug, 2021 16:46:48 Top
Andrei Smolin


Add-in Express team


Posts: 17953
Joined: 2006-05-11
Hello Michael,

In what event do you do this?

Regards from Poland (CEST),

Andrei Smolin
Add-in Express Team Leader
Posted 27 Aug, 2021 05:00:43 Top
Michael Kaden




Posts: 322
Joined: 2017-11-15
Hello Andrei,

just see that you are in Poland. Wishing you all the best. I have Polish ancestors.

I have a WPF usercontrol with a button.

The WPF usercontrol is Elementhost in a WinForm

The button_click event in the WPF usercontrol has the code to add the BookNow.CustomDocumentProperties.Add("x", "W")

Thank you very much and kind regards

Michael
Posted 27 Aug, 2021 06:02:15 Top
Andrei Smolin


Add-in Express team


Posts: 17953
Joined: 2006-05-11
Thank you, Michael!

Then the issue comes from that exact line. At https://docs.microsoft.com/en-us/office/vba/api/office.documentproperties.add they describe the parameters of the DocumentProperties.Add() method.

Regards from Poland (CEST),

Andrei Smolin
Add-in Express Team Leader
Posted 27 Aug, 2021 06:18:58 Top
Michael Kaden




Posts: 322
Joined: 2017-11-15
Dear Andrei,

thank you very much for your reply. I was aware of that documentation and have already looked at all the docs.microsoft.doc for the DocumentProperty object and DocumentProperties object

This:

Dim BookNow As Excel.Workbook = alera.AddinModule.CurrentInstance.GetActiveWorkbook
BookNow.CustomDocumentProperties.Add(Name:="LastModifiedBy", LinkToContent:=False, Type:=msoPropertyTypeString, Value:="hallo")


raised the wrong argument error

I found out that I do actually access he Custom Properties as:

 BookNow.CustomDocumentProperties.Count


returns the correct count

Finally I was sucessfull in my Internet search

msoPropertyTypeString

When I replace

Type:=msoPropertyTypeString

by

Type:=4

it works perfect.

Do you know why this can happen?

Thank you & have a good start in too the new week-

kind regards

Michael
Posted 29 Aug, 2021 13:56:02 Top
Andrei Smolin


Add-in Express team


Posts: 17953
Joined: 2006-05-11
Hello Michael,

Your first call used positional arguments and the second argument should be Type. Or it should be marked as missing: BookNow.CustomDocumentProperties.Add("x", , "W"). Your second call uses the named arguments.

Regards from Poland (CEST),

Andrei Smolin
Add-in Express Team Leader
Posted 30 Aug, 2021 03:27:21 Top
Andrei Smolin


Add-in Express team


Posts: 17953
Joined: 2006-05-11
And thank you, Michael!

Regards from Poland (CEST),

Andrei Smolin
Add-in Express Team Leader
Posted 30 Aug, 2021 03:32:30 Top
Michael Kaden




Posts: 322
Joined: 2017-11-15
Hallo Andrei,

if you look at my last message:

BookNow.CustomDocumentProperties.Add(Name:="LastModifiedBy", LinkToContent:=False, Type:=msoPropertyTypeString, Value:="hallo")

DID NOT WORK

BookNow.CustomDocumentProperties.Add(Name:="LastModifiedBy", LinkToContent:=False, Type:=4, Value:="hallo")

DID WORK


So why is an error raised that msoPropertyTypeString is the wrong argument? In the hyperlink of my last message I found someone who solved it in the same way, but no clue why this happens. I would like to find the root of the problem to avoid similar errors happen elsewhere from the same root cause.

Perhaps there is some reference or Import statement missing in my solution?

thank you & kind regards

Michael
Posted 30 Aug, 2021 03:39:45 Top