![]() |
#1
|
||||
|
||||
![]()
Context
I'm trying to do some automation of a document and embed information into the template I'm developing. Need: I need to be able to have a quick and easy way for a user to choose a document property and assign it without having to go through advanced properties and modifying them. I'm amenable to a pop-up, a user-form, whatever it takes! Ideally, I'd like a way for the user to choose a location/document property when they create a new document from this document template I'm creating. It really only needs to be chosen upon the creation of the document and likely won't be changed afterwards. Current approach I am using a custom document property called "Field_Office" to automate certain things, such as the field office location content control values (such as address, city, state, etc.), the banner image of the document (which includes address information and may allow for updated graphics in the future), etc. I've gotten that part working, but assigning the Field_office property is not an intuitive thing, and I'm afraid users simply won't go through the steps necessary to reassign that particular property. Alternatively, I've been trying to figure out a way to maybe link/assign the document property from a drop-down content control such as this XML: Code:
<Field_office_Dropdown> <location>Portland</location> <location>Seattle</location> <location>Los Angeles</location> <location>Denver</location> </Field_Office_Dropdown> My attempts at linking this easy user interface have failed and I'm not adept enough in Visual Basic to follow anything that is going on in all the forum channels I've read (and I've been reading for about 10 hours now...). I've done research and training on VB and the most basic document properties and object properties I can't even seem to declare successfully. I do understand programming, but the complexities of Word's objects are a lot to take on all at once. That said, if I could just get past declaring the bloody variable, I would be on a better course of action! I have tried following directions to a T, but I can't even figure out how to create a bookmark... and I considered myself pretty good at Word before encountering this issue!! ![]() Might anyone be able to help? I included an example, stripped of my failed attempts at macros. ![]() |
#2
|
||||
|
||||
![]()
Hi thedr9wningman,
For your address data and logos, you could probably get away with using just a single document property (e.g. the 'Office' property), coupled with INCLUDETEXT and, perhaps, INCLUDEPICTURE fields that reference the fuller details in external files. This would be much easier to code & maintain than putting it all into a macro. The INCLUDETEXT field would reference either a separate file for each location or a nominated bookmark within a common file shared by all locations. The code to update both the document property and the corresponding logo & address would then be as simple as; Code:
Sub Demo() With ActiveDocument .CustomDocumentProperties("Office").Text = InputBox("What is your Office location?", "Home Base") .Fields.Update .Fields.Unlink End With End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
||||
|
||||
![]()
Hi Paul:
Thanks for your response. I'm not sure I totally understand it, but when I've tried running that code, I get a runtime error #5: Invalid procedure call on the line: Code:
.CustomDocumentProperties("Office").Text = InputBox("What is your Office location?", "Home Base") Thank you for your assistance. |
#4
|
|||
|
|||
![]()
Yeah basically,
The properties listed as custom properties don't really exist until you use the name and assign a value: Code:
Sub ScratchMacro() 'A basic Word macro coded by Greg Maxey Dim oCP As DocumentProperty With ActiveDocument On Error Resume Next Set oCP = .CustomDocumentProperties("Office") If Not Err.Number = 0 Then Set oCP = .CustomDocumentProperties.Add(Name:="Office", LinkToContent:=False, Value:=InputBox("What is your Office location?", "Home Base"), Type:=msoPropertyTypeString) Else oCP.Value = InputBox("What is your Office location?", "Home Base") End If On Error GoTo 0 Debug.Print oCP.Value End With End Sub |
![]() |
Tags |
content controls, docproperty, document properties |
Thread Tools | |
Display Modes | |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
KJJ | Word VBA | 14 | 11-10-2016 08:18 PM |
![]() |
cheffx1265 | Word VBA | 1 | 04-05-2013 05:25 AM |
Key shortcut to access document properties | eroock | Word | 0 | 12-11-2012 10:54 AM |
document properties issues | charris1980 | Word | 0 | 04-29-2009 12:49 PM |