

The first is the name of the property, and the second specifies whether the property is linked to the contents of the document. When creating a custom document property, the add method requires four or five different values.

The $arrayArgs variable stores this information. Next, an array with the custom property name and the value of the custom property is created. This type will be used later on in the script: The CustomDocumentProperties type is stored in the $typeCustomProperties variable. It is time to retrieve the CustomDocumentProperties type by using the GetType method. The object is stored in the $customProperties variable: Obtain the CustomDocumentProperties collection by calling the CustomDocumentProperties property. The BindingFlags class will be used several times in the Set-WordCustomProperties.ps1 script: This is stored in the $binding variable as shown here. This is seen here:īecause of the way that the COM interop works, the BindingFlags class from the System.Reflection namespace needs to be created as a type. It is time to open the Microsoft Word document, and to store the returned Document object in the $document variable. When the Word.Application object is stored in the $application variable, the visible property is set to false to keep the Word document from displaying on the screen.

When working with Microsoft Word, it is generally a requirement to create an instance of the Word.Application COM object. The reason I left that part out of the script is that the script was already rather complicated, and I did not want to clutter it up anymore than it already was: In reality, this could be a Get-ChildItem cmdlet that filters all of the document files, in the same manner that was used in yesterday’s Excel article. JB, the first thing to do is to assign the path to the document. “Delete”, $binding::InvokeMethod,$null,$propertyObject,$null) “Item”, $binding::GetProperty,$null,$customProperties,$CustomProperty) $propertyObject = $typeCustomProperties.InvokeMember(` “add”, $binding::InvokeMethod,$null,$customProperties,$arrayArgs) | $arrayArgs = $CustomProperty,$false, 4, $Value $typeCustomProperties = $customProperties.GetType() $customProperties = $document.CustomDocumentProperties $application = New-Object -ComObject word.application The complete Set-WordCustomProperties.ps1 script is seen here. You should refer to the Hey, Scripting Guy! post you mentioned in your e-mail message for information about working with custom properties in Microsoft Word, as well as for additional information about working with the InvokeMember method. JB, I decided to write the Set-WordCustomProperties.ps1 script for you to allow you to set custom properties on a Microsoft Word document. Thinking of Jit reminded me of some of the pictures I took during that trip, such as the following one that was taken in downtown Brisbane. He was the Microsoft guy that I was to train to deliver my class and I got to work with him for two weeks-one week in Brisbane and one in Sydney. I first met Jit several years ago in Brisbane, Australia, when I went there to teach a VBScript class that was based upon one of my VBScript books. I knew it was Jit because I recognized his e-mail address. She took her laptop with her and muttered something about me being “impossible at times”-as if she weren’t alive in the 1970s or something.Īnyway, as I was reviewing the e-mail inbox, I ran across Jit’s message. She evacuated the upstairs about the time that Sunshine of Your Love came on, and she was long gone by the time Badge was playing. I have no idea where the Scripting Wife is right now. I have Cream cranked up so loud on my Zune HD that I can feel the energetic Jack Bruce bass licks deep inside my bones, and therefore I am sipping, munching, and grooving as I review the e-mail sent to the address. I was able to score some Tim Tams from my friend Brent in Sydney recently while he was in the United States for the Microsoft TechReady conference in Seattle, Washington, so things are progressing nicely this morning. I am sipping a cup of English Breakfast tea with a little lemon grass and a stick of cinnamon in it. I am wondering if you would care to tackle that task now?
Add document properties word how to#
You, however, did not show how to modify the value of custom properties.
Add document properties word windows#
The post illustrated how to use Windows PowerShell to read the custom properties from Microsoft Word documents. Hey, Scripting Guy! A few months ago, you wrote a really cool Hey, Scripting Guy! post, How Can I Retrieve the Custom Properties of a Microsoft Word Document.
