Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-21-2014, 07:28 AM
pmcen08 pmcen08 is offline Edit Custom Doc Properties using Macros Windows 7 64bit Edit Custom Doc Properties using Macros Office 2010 64bit
Novice
Edit Custom Doc Properties using Macros
 
Join Date: Nov 2014
Posts: 1
pmcen08 is on a distinguished road
Default Edit Custom Doc Properties using Macros

Hi All,

I am trying to simplify the process of entering custom document property values in word. My idea is to:

• Set up at table at the beginning of the document where the user will enter in the custom document property values. See example below;


Doc. Property....................Value
Product Name .............Machine 500
Manufacturer ............Blogs Machines Ltd.

• Use Marcos to take the data entered into a cell (Machine 500) and copy it,

• Open the advanced properties menu and select the Product Name property, in the value text box paste (Machine 500), click modify and return to the document

• Select all items, (Ctrl+A) and then update all fields (F9) All custom fields/document properties should now be updated to (Machine 500)


I am new to Macros and VBA, I have made an attempt using Macros, but it doesn’t work.

Is this even the right method? Is there a better way?
Any help appreciated!
Reply With Quote
  #2  
Old 11-21-2014, 11:53 AM
gmaxey gmaxey is offline Edit Custom Doc Properties using Macros Windows 7 32bit Edit Custom Doc Properties using Macros Office 2010 (Version 14.0)
Word MVP 2003-2009
 
Join Date: May 2010
Location: Marble, NC
Posts: 1,007
gmaxey will become famous soon enoughgmaxey will become famous soon enough
Default

Where is your attempt?

Code:
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim oTbl As Word.Table
Dim oProp As DocumentProperty
Dim lngIndex As Long
  Set oTbl = ActiveDocument.Tables(1)
  For lngIndex = 2 To oTbl.Rows.Count
    On Error GoTo Err_Property
    Set oProp = ActiveDocument.CustomDocumentProperties(fcnCellText(oTbl.Cell(lngIndex, 1)))
    oProp.Value = fcnCellText(oTbl.Cell(lngIndex, 2))
NextEntry:
  Next lngIndex
  ActiveDocument.Fields.Update
lbl_Exit:
  Exit Sub
Err_Property:
  ActiveDocument.CustomDocumentProperties.Add _
    Name:=fcnCellText(oTbl.Cell(lngIndex, 1)), LinkToContent:=False, Value:=fcnCellText(oTbl.Cell(lngIndex, 2)), _
    Type:=msoPropertyTypeString
  Resume NextEntry
End Sub
Function fcnCellText(oCell As Word.Cell) As String
  fcnCellText = Replace(oCell.Range.Text, Chr(13) + Chr(7), "")
  
End Function
I wouldn't use that method. I would create a Product Name and Manufacture content control, map them to a customXMLnode and then copy and paste the controls where I need the same data repeated.
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 11-21-2014, 02:12 PM
macropod's Avatar
macropod macropod is offline Edit Custom Doc Properties using Macros Windows 7 64bit Edit Custom Doc Properties using Macros Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 20,042
macropod has much to be proud ofmacropod has much to be proud ofmacropod has much to be proud ofmacropod has much to be proud ofmacropod has much to be proud ofmacropod has much to be proud ofmacropod has much to be proud ofmacropod has much to be proud ofmacropod has much to be proud ofmacropod has much to be proud of
Default

To add and update Custom Document Properties, see: http://support.microsoft.com/kb/212618/
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Add custom doc properties in "Doc properties control" eazysnatch Word 2 09-13-2017 08:08 PM
Searching with Custom Properties jpb103 Word VBA 6 05-30-2014 07:08 AM
Batch edit mail merge macros? kbash Word 0 04-30-2014 08:32 AM
Custom Properties b-baker Word 1 03-01-2012 01:15 AM
Looping though Custom Properties in VBA suekay Misc 0 05-19-2006 06:10 AM


All times are GMT -7. The time now is 07:13 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2020 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft