Avatar of AIBMass
AIBMass

asked on 

How to control line spacing with Word 2010 Automation

Version 1:

When I open a document in WOrd 2010, there is a button on the ribbon to change the paragraph  (or is it the lines in a paragraph?) spacing from "normal" to "no spacing".

What is the automation equivalent of this button?


Version 2:

I have this line of code in my vb.net project that automates Word:

        wordApp.Selection.ConvertToTable(NumColumns:=2)

This does not produce the exact same result as my doing Convert To Table in the regular app because the line spacing is different. When I do it in Word, the line spacing appears to go to No Spacing, but using Automation there is still space between the lines.

How do I make the automated version look like the manually create version?
Why are the two versions different?

Thanks.
Microsoft WordMicrosoft Office

Avatar of undefined
Last Comment
AIBMass
ASKER CERTIFIED SOLUTION
Avatar of Gerwin Jansen
Gerwin Jansen
Flag of Netherlands image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of AIBMass
AIBMass

ASKER

GerwinJansen:

Fantastic!

Actually it is one question approached from two angles. The first question is how do I make it work and your solution is perfect.

The related question is why do I have to do this when automating, but not have to change the spacing (via the ribbon) when just using Word as an application? It seems like the ConvertToTable method is not behaving exactly the same as the Convert Text to Table functionality in the app. Can anyone verify or explain this?

Can you shed some light on this? I hope to understand this just a bit better and on Monday I will award the points.

Thanks!
:) What if you add options like Format, AutoFit, SetDefault or Style to your ConvertToTable call? You can look them up when you create your table using 'record macro'.
Avatar of AIBMass
AIBMass

ASKER

Another variation:

Selection.Style = mydoc.Styles("No Spacing")
Microsoft Office
Microsoft Office

Microsoft Office is an integrated suite of applications that includes Outlook, Word, Excel, Access, PowerPoint, Visio and InfoPath, along with a number of tools to assist in making the individual components work together. Coding within and between the projects is done in Visual Basic for Applications, known as VBA.

80K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo