Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-16-2015, 06:01 AM
macropod's Avatar
macropod macropod is offline Batch re-naming Windows 7 64bit Batch re-naming Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

OK, so you have a badly-formatted document, with paragraph breaks instead of line breaks between consecutive lines, and yet more paragraph breaks for inter-paragraph spacing, along with pointless tabs!



Given that scenario, you could use something like:
Code:
Sub PolicyDocs()
Application.ScreenUpdating = False
Dim strFolder As String, strFile As String, StrName As String, wdDoc As Document
strFolder = GetFolder
If strFolder = "" Then Exit Sub
strFile = Dir(strFolder & "\*.doc", vbNormal)
While strFile <> ""
  If Not strFile Like "Policy[*].doc" Then
    StrName = ""
    Set wdDoc = Documents.Open(FileName:=strFolder & "\" & strFile, AddToRecentFiles:=False, Visible:=False)
    With wdDoc
      With .Range
        With .Find
          .ClearFormatting
          .Text = "Policy[!^13]{1,}"
          .MatchWildcards = True
          .Forward = True
          .Wrap = wdFindStop
          .Execute
        End With
        If .Find.Found Then StrName = .Text
      End With
      If StrName <> "" Then .SaveAs FileName:=.Path & "\" & StrName & ".doc"
      .Close
    End With
  End If
  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
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #2  
Old 06-16-2015, 12:29 PM
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
Default

Thank you both!
Reply With Quote
Reply



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 06:36 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