![]() |
#1
|
|||
|
|||
![]()
How would you revise this macro in order to search for "Policy _________"? Would you be able to search within document and essentially copy and paste "Policy _________" to save as new document name? I actually tried to use a macro (copied below) however I am getting a Runtime error 4198 for .SaveAs FileName:=FirstPara & ".doc".
Help, please ![]() Sub FirstPara() Application.ScreenUpdating = False Dim strFolder As String, strFile As String, wdDoc As Document Dim FirstPara As String 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 FirstPara = .Paragraphs(1).Range.Text FirstPara = Left(FirstPara, Len(FirstPara) - 1) .SaveAs FileName:=FirstPara & ".doc" .Close End With Set wdDoc = Nothing strFile = Dir() Wend 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 Last edited by macropod; 06-15-2015 at 04:44 PM. Reason: Split from http://www.msofficeforums.com/word-vba/23610-how-rename-word-doc-name-mentioned-body.html |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Naming Cells for formula referencing | lynchbro | Excel | 6 | 06-26-2014 07:45 AM |
Naming plot-line breaks dates on x-axis | Sammael | Excel | 0 | 06-01-2013 03:29 PM |
![]() |
JDevsFan | Excel Programming | 4 | 03-15-2012 08:44 AM |
Auto file naming | Rong Peng | Word VBA | 0 | 07-29-2011 07:37 AM |
Auto-File Naming/ Default Directory Saves | sgill32 | Word | 2 | 11-06-2008 02:12 PM |