|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Extract Document Property and insert it into the same document, for many files in a folder
I would like to extract a Document Property "Title" and insert it into the same document, just at the beginning. There is most likely text at that location, it can go before or after just as long as it is inserted once, for many files in one folder. I found code by macropod about opening a document, running macro, then closing and saving document, all located in one folder. I figured inserting the Title like a quick part code would work but doesn't seem to, I don't want to go in all 300 files and add bookmarks, and all files already have the document property 'Title' filled out. Huge n00b here Code:
Sub UpdateDocuments() Application.ScreenUpdating = False Dim strFolder As String, strFile As String, wdDoc As Document strFolder = GetFolder If strFolder = "" Then Exit Sub strFile = Dir(strFolder & "\*.doc", vbNormal) While strFile <> "" Set wdDoc = Documents.Open(FileName:=strFolder & "\" & strFile, AddToRecentFiles:=False, Visible:=False) With wdDoc 'Call your other macro or insert its code here- NO IDEA HERE.... Selection.HomeKey = wdStory ActiveDocument.Range.InsertAfter "DocPROPERTY Title" ' .Close SaveChanges:=True End With strFile = Dir() Wend Set wdDoc = Nothing Application.ScreenUpdating = True End Sub Function GetFolder() As String Dim oFolder As Object GetFolder = "" Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0) If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path Set oFolder = Nothing End Function |
#2
|
||||
|
||||
That's as simple as:
Code:
With wdDoc .Range.InsertBefore .BuiltInDocumentProperties("Title") & vbCr .Close SaveChanges:=True End With
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
Tags |
document, extract, property |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
From a docx report document save all images in a cell from the document to a folder | censura | Word VBA | 1 | 05-13-2017 12:54 AM |
Vba code to save document as pdf using document property text and rename folder. | staicumihai | Word VBA | 1 | 12-21-2015 07:39 AM |
Document Property Question | ksigcajun | Word VBA | 9 | 10-14-2014 11:26 AM |
Insert image based on document custom property | anandyrh | Word | 1 | 08-14-2013 12:08 AM |
Remove title property from all files in a folder | konopca | Word VBA | 2 | 12-04-2012 10:54 AM |