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