Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word Macros 1

Status
Not open for further replies.

SS-WRD

Technical User
Jul 23, 2020
5
US
Hello All,
I am hoping someone can help me with some Word macros.

We have several macros that were created long before me and up until recently they worked find using Office 2016. However, we have switched over to Office 2019 and now they work but not quite right. What I mean by that is, while for the most part the macros work, the line spacing is off. Below is a snippet of one of the macros. Where it says, "WordBasic.insertpara" it should drop down to the next line, which it does. However, the line spacing used to be single space and is now double spaced. How do I fix this to get it to work with our new version of Office?


Public Sub MAIN()
Dim Nme$
Dim N$
Dim Addr$
Dim A$
Dim Csz$
Dim C$
Dim Acct$
Dim Ac$
Dim Ploc$
Dim Loc_$
Dim Bal$
Dim Dbal$
Dim Sal$
Dim S$
Dim Ploc2$
Dim Loc2$
Dim Dt$
Dim D$
Dim Ploc3$
Dim Loc3$
Dim Dt2$
Dim D2$
Rem ACTUAL
Rem Collection letter
Rem Changed Bev Eick to E. Borsini
Rem Changed Borsini to McRae
With ActiveDocument.PageSetup
.LineNumbering.Active = False
.Orientation = wdOrientPortrait
.TopMargin = InchesToPoints(1)
.BottomMargin = InchesToPoints(1)
.LeftMargin = InchesToPoints(1)
.RightMargin = InchesToPoints(1)
.Gutter = InchesToPoints(0)
.HeaderDistance = InchesToPoints(0)
.FooterDistance = InchesToPoints(0)
.PageWidth = InchesToPoints(8.5)
.PageHeight = InchesToPoints(11)
.FirstPageTray = wdPrinterLowerBin
.OtherPagesTray = wdPrinterLowerBin
.SectionStart = wdSectionNewPage
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = False
.VerticalAlignment = wdAlignVerticalTop
.SuppressEndnotes = False
.MirrorMargins = False
End With
WordBasic.RightPara
WordBasic.InsertField Field:="CREATEDATE \@ " + Chr(34) + "MMMM d, yyyy" + Chr(34) + " \* MERGEFORMAT"
WordBasic.CharLeft 1
WordBasic.UnlinkFields
WordBasic.CharRight 1
WordBasic.insertpara
WordBasic.insertpara
WordBasic.JustifyPara
Nme$ = WordBasic.[InputBox$]("Please enter customer name", N$)
WordBasic.insert Nme$
WordBasic.insertpara
Addr$ = WordBasic.[InputBox$]("Please enter customer address", A$)
WordBasic.insert Addr$
WordBasic.insertpara
Csz$ = WordBasic.[InputBox$]("Please enter city, state and zip code", C$)
WordBasic.insert Csz$
[highlight #FCE94F]WordBasic.insertpara
WordBasic.insertpara[/highlight]
WordBasic.insert "Re: Account Number: "
Acct$ = WordBasic.[InputBox$]("Please enter account number", Ac$)
WordBasic.insert Acct$
WordBasic.insertpara
WordBasic.insert "Property Location:
 
Before you do any corrections to your macros, I would open Word and check Layout - Spacing settings:

Spacing_jpknsb.png


I had to re-set mine to 0's (in Normal.dotm) with new version of Word.

Or, you can add to the beginning of your macros:
Code:
Selection.WholeStory
With Selection.ParagraphFormat
    .SpaceBefore = 0
    .SpaceAfter = 0
End With

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
My "after" was set to 8. Setting it to 0 did the trick on mine. I didn't look there as it has affected everyone so I can only assume it is a default setting.

Thanks for the help!
 
You might want to award Andy a purple star! It is the general etiquette on this site. You just need to click "Great Post
 
Hard formatting, as demonstrated by Andrzejek's post should be avoided. That approach leads to document bloat and increases the risk of document corruption.

The simple solution - which requires no programming at all - is to modify Word's Normal Style. Done in Word's Normal template, this need be done only once, since it will apply to all future documents. Alternatively, base your macro-generated documents on a different template, in which Word's Normal Style is suitably configured. Indeed, with a properly-configured template, you'd need none of the 21 lines of code you now have for setting the page layout. The manner with which the date is inserted is also appallingly inefficient.

Of course, if you're absolutely wedded to doing the line & paragraph spacing in code, it's as simple as:
Code:
With ActiveDocument.Styles(wdStyleNormal).ParagraphFormat
  .SpaceBefore = 0
  .SpaceAfter = 0
  .LineSpacingRule = wdLineSpaceSingle
End With

BTW: That old code is mix of WordBasic and VBA. Someone really ought to update it...

Cheers
Paul Edstein
[Fmr MS MVP - Word]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top