RE: Convert Macro to run in 2007
- From: StevenM <stevencraigmiller(at)comcast(dot)net>
- Date: Mon, 2 Jun 2008 07:11:01 -0700
To: Anthony,
I would help if you would tell us what this macro is supposed to accomplish.
I might be mistaken, but my guess is that this macro:
(1) scans the first 150 lines to see if one of the lines is greater than 80
characters long;
(2) it changes the font; and
(3) if one of the lines scaned was greater than 80 characters, then it
changes the page layout, while deleting the header and footer.
Is that it? Or is there more to it?
I've made the assumption that each line of your document ends with a
paragraph mark. If I'm wrong, ignore my message.
If my assumptions have been correct, you might try running this macro.
Public Sub DoAdmin()
Dim oDoc As Document
Dim nMaxPara As Long
Dim nIndex As Long
Dim nLineLen As Long
Set oDoc = ActiveDocument
'
' While line length not greater than 80 characters
' Should be in first 150 Lines
'
nIndex = 1
nMaxPara = oDoc.Paragraphs.Count
nLineLen = Len(oDoc.Paragraphs(1).Range.Text)
If nMaxPara > 150 Then nMaxPara = 150
While (nIndex <= nMaxPara And nLineLen < 80)
nIndex = nIndex + 1
nLineLen = Len(oDoc.Paragraphs(nIndex).Range.Text)
Wend
'
' Now work on the document
' Set up font size 8 and font to Courier New
'
With oDoc.Range.Font
.Name = "Courier New"
.Size = 8
End With
'
' If the report has lines greater than 80 columns with format characters
' then need to print as landscape report
'
If nLineLen > 85 Then
' Remove header And footers For Text report
oDoc.Sections(1).Headers(wdHeaderFooterPrimary).Range.Delete
oDoc.Sections(1).Footers(wdHeaderFooterPrimary).Range.Delete
' Reduce margin size And set up landscape
With oDoc.PageSetup
.Orientation = wdOrientLandscape
.TopMargin = InchesToPoints(0.25)
.BottomMargin = InchesToPoints(0.26)
.RightMargin = InchesToPoints(1)
.LeftMargin = InchesToPoints(1)
End With
End If
' Put the user back at the top of the report
oDoc.Range(0, 0).Select
' End of Macro
End Sub
Steven Craig Miller
"Anthony B" wrote:
I've recently been given the task of transferring this Macro into Word 2007..
However although the Macro seems to work. It needs to be run twice.
Everything except the "If Len(Line_$) > 85 Then" routine runs first time.
On the 2nd run this routine does work.
Can anyone point me in the right direction.
Thanks
"
Public Sub DoAdmin()
Dim Line_$
Dim LineCount
'
' Format downloaded Admin Files
'
'
' Start at first line of document
'
WordBasic.StartOfDocument
'
' Get the line as a text string
'
Let Line_$ = WordBasic.[GetBookmark$]("\Line")
Let LineCount = 1
'
' While line length not greater than 80 columns
' Should be in first 150 Lines
' (Include CR/LF and more file to read)
'
While WordBasic.LineDown() And Len(Line_$) <= 85 And LineCount <= 150
'
' Get the next line and check the line size
'
Let Line_$ = WordBasic.[GetBookmark$]("\Line")
Let LineCount = LineCount + 1
Wend
'
' Now work on the document
'
WordBasic.EditSelectAll
'
' Set up font size 8 and font to Courier New
'
WordBasic.FormatFont Points:="8", Underline:=-1, Color:=-1,
StrikeThrough:=-1, Superscript:=-1, Subscript:=-1, Hidden:=-1, SmallCaps:=-1,
AllCaps:=-1, Spacing:="", Position:="", Kerning:=-1, KerningMin:="",
Tab:="0", Font:="Courier New", Bold:=0, Italic:=0
'
' If the report has lines greater than 80 columns with format characters
' then need to print as landscape report
'
If Len(Line_$) > 85 Then
'
' Remove header And footers For Text report
' reduce margin size And set up landscape
'
WordBasic.FilePageSetup Tab:="0", PaperSize:="1", TopMargin:="0.25" +
Chr(34), BottomMargin:="0.26" + Chr(34), LeftMargin:="1" + Chr(34),
RightMargin:="1" + Chr(34), Gutter:="0" + Chr(34), PageWidth:="11.69" +
Chr(34), PageHeight:="8.27" + Chr(34), Orientation:=1, FirstPage:=0,
OtherPages:=0, VertAlign:=0, ApplyPropsTo:=3, FacingPages:=0,
HeaderDistance:="0" + Chr(34), FooterDistance:="0" + Chr(34),
SectionStart:=2, OddAndEvenPages:=0, DifferentFirstPage:=0, Endnotes:=0,
LineNum:=0, StartingNum:="", FromText:="", CountBy:="0", NumMode:=-1
End If
'
' Put the user back at the top of the report
'
WordBasic.StartOfDocument
'
' End of Macro
'
End Sub
"
- Follow-Ups:
- RE: Convert Macro to run in 2007
- From: Anthony B
- RE: Convert Macro to run in 2007
- From: StevenM
- RE: Convert Macro to run in 2007
- References:
- Convert Macro to run in 2007
- From: Anthony B
- Convert Macro to run in 2007
- Prev by Date: RE: Repressing Word alerts?
- Next by Date: Problems when converting VBA code into Word 2007
- Previous by thread: Convert Macro to run in 2007
- Next by thread: RE: Convert Macro to run in 2007
- Index(es):
Relevant Pages
|