PDA

View Full Version : Solved: Code to scrape File Properties > Title & hold in Clipboard



Jedumi
03-17-2013, 08:10 AM
I need a macro (I'll assign it to an icon on a toolbar) to (quickly) copy the contents of the Title field in the current (active) document's properties (File > Properties) so that I can paste it somewhere. If someone can help me with this, I'll be grateful.

Additionally, (so that I can adapt the above) what are the VBA 'codes' for the Subject and Manager fields?

Thanks in advance...

Jedumi

fumei
03-17-2013, 10:35 AM
What have you tried so far. Please post what code you have tried, and what problems or issues you have with it.

Jedumi
03-17-2013, 07:55 PM
I tried to record a macro, but none of the steps was recorded. I don't speak enough VBA to try this from scratch.

Doug Robbins
03-18-2013, 12:48 AM
Use

Dim strTitle As String
Dim strSubject As String
Dim strManager As String
With ActiveDocument
strTitle = .BuiltInDocumentProperties(wdPropertyTitle)
strSubject = .BuiltInDocumentProperties(wdPropertySubject)
strManager = .BuiltInDocumentProperties(wdPropertyManager)
End With

Jedumi
03-18-2013, 10:07 PM
Thanks, Doug. Your post tells me the names of the various strings - thanks. But what extra code is needed to paste it at the insertion point?

Googling around, I see that it is best practice to bypass the Clipboard, or alternatively to preserve the clipboard contents prior to executing and restoring afterwards. What's your take?

Ideally, I'd like to invoke a macro that will place the (e.g.) wdPropertyTitle at the insertion point. Will you help me?

Doug Robbins
03-19-2013, 12:08 AM
Use



Selection.Text = ActiveDocument.BuiltInDocumentProperties(wdPropertyTitle)


Of course, from the User Interface, you can also insert a { DOCPROPERTY Title } field.

Jedumi
03-19-2013, 02:08 AM
Many thanks, Doug.