PDA

View Full Version : Solved: Document properties.



Sir Babydum GBE
11-21-2005, 04:49 AM
Hi,

I used the "record macro" feature and then started updating the document properties. When I stopped recording and checked the code, nothing was there. So how can a run a macro (from personal) to update the document properties of the open excel workbook?

Thanks for your help :yes

Marcster
11-21-2005, 05:12 AM
Hi Babydum :hi:,
The objects your after are:
BuiltinDocumentProperties and CustomDocumentProperties
There are several properties you can set, builtin and custom ones.
ActiveWorkbook.BuiltinDocumentProperties("Title").Value = "Title of workbook"
ActiveWorkbook.BuiltinDocumentProperties("Subject").Value = "Subject of workbook"
ActiveWorkbook.BuiltinDocumentProperties("Author").Value = "Author of workbook"
ActiveWorkbook.BuiltinDocumentProperties("Manager").Value = "Manager of workbook"
ActiveWorkbook.BuiltinDocumentProperties("Company").Value = "Company of workbook"

HTH,

Marcster.

Bob Phillips
11-21-2005, 05:41 AM
And this is how to create a custom property, which isn't obvious


With ActiveWorkbook
.CustomDocumentProperties.Add Name:="Babydum", LinkToContent:=False, _
Value:="Agony Aunt", Type:=msoPropertyTypeString
End With

Marcster
11-21-2005, 05:56 AM
Further to the above,
Here's a macro to add custom document properties:


Sub AddCustomWorkbookProperties()
Dim usrNum As Integer
Dim usrText As String
Dim usrDate As Date

usrNum = 123
usrText = "User text value here"
usrDate = VBA.Date

With ActiveWorkbook.CustomDocumentProperties
.Add Name:="CustomPropertyNumber", _
LinkToContent:=False, _
Type:=msoPropertyTypeNumber, _
Value:=usrNum
.Add Name:="CustomPropertyString", _
LinkToContent:=False, _
Type:=msoPropertyTypeString, _
Value:=usrText
.Add Name:="CustomPropertDate", _
LinkToContent:=False, _
Type:=msoPropertyTypeDate, _
Value:=usrDate
End With
End Sub

HTH,

Marcster

Sir Babydum GBE
12-12-2005, 05:18 AM
Every now and again I run a search of my posts, and am horrified to see that I didn't say thanks to the answerers.

It's forgetfulness, not arrogance - so please accept my apologies.

Thanks both!

Bob Phillips
12-12-2005, 05:26 AM
Every now and again I run a search of my posts, and am horrified to see that I didn't say thanks to the answerers.

It's forgetfulness, not arrogance - so please accept my apologies.

Thanks both!

What can we say, a Welsh Tyke.