View Single Post
 
Old 12-07-2017, 09:54 AM
MisrIdley MisrIdley is offline Windows 10 Office 2013
Novice
 
Join Date: Dec 2017
Posts: 1
MisrIdley is on a distinguished road
Unhappy 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
Reply With Quote