# Word 07 macro, Run-time  5097 error.



## kraft_mk (Apr 3, 2011)

Hope you can help me.
I created this very simple Word 2007 recorded macro for fixing the page margins and font in a .txt file created in diferent old program.
Worked for a long time without any problems.

Suddenly now, when I ran the  macro I am getting this 5097 run-time error.
Debag getts me to this line : 
*With ActiveDocument.Styles(wdStyleNormal).Font*

If I record another one, I have the same problem.

Thanks for your help!
__________________________________________________________
The code:

Sub CP_sreduvanje_snimanje_prakanje_printanje()
'
' CP_sreduvanje_snimanje_prakanje_printanje Macro
'
'
    Selection.Delete Unit:=wdCharacter, Count:=1
    Selection.Delete Unit:=wdCharacter, Count:=1
    Selection.WholeStory
        Selection.Font.Name = "Courier New"
    Selection.Font.Size = 7
        With ActiveDocument.Styles(wdStyleNormal).Font
        If .NameFarEast = .NameAscii Then
            .NameAscii = ""
        End If
        .NameFarEast = ""
    End With
    With ActiveDocument.PageSetup
        .LineNumbering.Active = False
        .Orientation = wdOrientPortrait
        .TopMargin = CentimetersToPoints(5#)
        .BottomMargin = CentimetersToPoints(4.3)
        .LeftMargin = CentimetersToPoints(0.5)
        .RightMargin = CentimetersToPoints(0.5)
        .Gutter = CentimetersToPoints(0)
        .HeaderDistance = CentimetersToPoints(1.25)
        .FooterDistance = CentimetersToPoints(1.25)
        .PageWidth = CentimetersToPoints(21)
        .PageHeight = CentimetersToPoints(29.7)
        .FirstPageTray = wdPrinterDefaultBin
        .OtherPagesTray = wdPrinterDefaultBin
        .SectionStart = wdSectionNewPage
        .OddAndEvenPagesHeaderFooter = False
        .DifferentFirstPageHeaderFooter = False
        .VerticalAlignment = wdAlignVerticalTop
        .SuppressEndnotes = False
        .MirrorMargins = False
        .TwoPagesOnOne = False
        .BookFoldPrinting = False
        .BookFoldRevPrinting = False
        .BookFoldPrintingSheets = 1
        .GutterPos = wdGutterPosLeft
    End With
    ActiveDocument.Save

End Sub


----------



## Macropod (Apr 9, 2011)

Hi Kraft,

When posting code, please use code tags. The following works for me (without the use of Selections):

```
Sub CP_sreduvanje_snimanje_prakanje_printanje()
With ActiveDocument
  .Range(0, 2).Delete
  .Content.Style = wdStyleNormal
  With .Styles(wdStyleNormal)
    With .Font
      .Name = "Courier New"
      .Size = 7
      If .NameFarEast = .NameAscii Then
        .NameAscii = ""
      End If
      .NameFarEast = ""
    End With
  End With
  With .PageSetup
    .PageWidth = CentimetersToPoints(21)
    .PageHeight = CentimetersToPoints(29.7)
    .LineNumbering.Active = False
    .Orientation = wdOrientPortrait
    .TopMargin = CentimetersToPoints(5#)
    .BottomMargin = CentimetersToPoints(4.3)
    .LeftMargin = CentimetersToPoints(0.5)
    .RightMargin = CentimetersToPoints(0.5)
    .Gutter = CentimetersToPoints(0)
    .HeaderDistance = CentimetersToPoints(1.25)
    .FooterDistance = CentimetersToPoints(1.25)
    .FirstPageTray = wdPrinterDefaultBin
    .OtherPagesTray = wdPrinterDefaultBin
    .SectionStart = wdSectionNewPage
    .OddAndEvenPagesHeaderFooter = False
    .DifferentFirstPageHeaderFooter = False
    .VerticalAlignment = wdAlignVerticalTop
    .SuppressEndnotes = False
    .MirrorMargins = False
    .TwoPagesOnOne = False
    .BookFoldPrinting = False
    .BookFoldRevPrinting = False
    .BookFoldPrintingSheets = 1
    .GutterPos = wdGutterPosLeft
  End With
  .Save
End With
End Sub
```
I am not sure though what you think this will achieve with a .txt file - as soon as you save it back to the .txt format, all of the re-formatting will be lost.


----------

