Thread: [Solved] Loop Macro to Edit Date
View Single Post
 
Old 12-05-2013, 08:28 AM
macropod's Avatar
macropod macropod is offline Windows 7 32bit 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

I've just run the following test macro on the document you uploaded:
Code:
Sub Test()
Dim StrRep As String, wdDoc As Document
StrRep = Format(DateAdd("d", -1, CDate(Month(Now()) & "/1/" & Year(Now()))), "MMMM D, YYYY")
Set wdDoc = ActiveDocument
  With wdDoc
    With .Range.Find
      .ClearFormatting
      .Replacement.ClearFormatting
      .Forward = True
      .Wrap = wdFindStop
      .Format = False
      .MatchWildcards = True
      .Replacement.Text = StrRep
      .Text = "[ADJMO][abceghlmnorstuy]{2,7} 31, [12][0-9]{3}"
      .Execute Replace:=wdReplaceAll
      .Text = "February 2[89], [12][0-9]{3}"
      .Execute Replace:=wdReplaceAll
      .Text = "[AJSN][beilmnoprtuv]{4,8} 30, [12][0-9]{3}"
      .Execute Replace:=wdReplaceAll
    End With
    .ExportAsFixedFormat OutputFileName:="C:\Users\" & Environ("UserName") & "\Documents\Test.pdf", _
      ExportFormat:=wdExportFormatPDF, OptimizeFor:=wdExportOptimizeForPrint
  End With
End Sub
and produced the attached pdf. The date is wrong, but that's because my regional settings aren't configured for US dates. As you can see, there's no issue with the borders.

As for the run-time error, that suggests you or another user already had open the document the code was trying to open. I trust you weren't trying to open the one you were running the macro from (i.e. don't save it to the folder you're trying to process).
Attached Files
File Type: pdf Test.pdf (113.3 KB, 11 views)
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote