Word 07 macro, Run-time 5097 error.

kraft_mk

New Member
Joined
Oct 5, 2009
Messages
23
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
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Hi Kraft,

When posting code, please use code tags. The following works for me (without the use of Selections):
Code:
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.
 
Upvote 0

Forum statistics

Threads
1,216,151
Messages
6,129,162
Members
449,489
Latest member
spvclub

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top