![]() |
|
#1
|
||||
|
||||
![]()
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] |
#2
|
|||
|
|||
![]()
Thank you both!
![]() |
![]() |
|
![]() |
||||
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 |