A
Anthony B
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
"
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
"