Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 06-15-2015, 09:11 AM
twols26 twols26 is offline Batch re-naming Windows 7 32bit Batch re-naming Office 2010 32bit
Novice
Batch re-naming
 
Join Date: Jun 2015
Location: Canada
Posts: 4
twols26 is on a distinguished road
Post Batch re-naming

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
Reply With Quote
 



Similar Threads
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
Batch re-naming re-naming arrays in VBA? 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

Other Forums: Access Forums

All times are GMT -7. The time now is 08:44 AM.


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