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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to determine the value of Microsoft Word 2010 constants

Status
Not open for further replies.

lpeder6

Programmer
Jan 30, 2019
10
0
0
US
This is in relation to my previous post modifying and formatting microsoft word document.

I'm working on some code from another developer who is no longer with the company. He created a script to find text, use HomeKey and EndKey, and move things around. To learn more since I can't ask him outright, I Googled the following line in hopes for a breakdown in how it works:

[pre]objWrd.Selection.HomeKey 6, 0[/pre]

The closest thing I can find on any of the many web sites I've visited is this for VBA:

[pre]Selection.HomeKey Unit:=wdStory, Extend:=wdMove[/pre]

Any idea how the previous developer may have modified the latter to get the VBScript version?
 
Probably started with the object model documentation …
For example the documentation for the Selection object describes the Extend parameter of the HomeKey method as a member of the WdMovementType enumerations. That enumeration is documented as:

[pre][tt]Name Value Description
wdExtend 1 The end of the selection is extended to the end of the specified unit.
wdMove 0 The selection is collapsed to an insertion point and moved to the end of the specified unit. Default.[/tt][/pre]

It is unfortunately perhaps less clear or explicit that the Unit parameter is a member of the wdUnit enumeration (documented here)
 
I guess I've got a lot to learn. I've used constants for the FileSystemObject, and those were easy to find. I guess you need to know where/how to look.

I was able to decipher how to insert a bit of text within a space between two paragraphs and make the insertion invisible.

I used this to count how many paragraphs are in the letter:

[pre]iParCount = objWrd.ActiveDocument.Paragraphs.Count[/pre]

Then, I had to put an 8 point space after the date within the letter. This is because if I tried to enter text within either of the two spaces between the date and the salutation, it replaced the space entirely. This space had to be left in there, and 8 point, along with the 12 point text and another 8 point space made it seem like I had done nothing. Here's how:

[pre]objWrd.ActiveDocument.Paragraphs(6).SpaceAfter = 8 ' 8 point space
objWrd.ActiveDocument.Paragraphs(7).Range.Font.ColorIndex = 8 ' wdWhite = White color
objWrd.ActiveDocument.Paragraphs(7).Range.Text = "DPS$$$PKG"
objWrd.ActiveDocument.Paragraphs(7).SpaceAfter = 8[/pre]

Still trying to figure out how to reformat the rest of the letter, but I'm learning. :)
 
Sadly, the company security on my computer won't let me download the file.

I'm trying to figure out how to shift a block, or line, of text a few spaces to the right or to the left. I thought this would work, but it just removed the first word in the line of text:

[pre]objWrd.ActiveDocument.Paragraphs(18).LeftIndent = 5[/pre]

I wish there was more clear documentation on how to manipulate the Word DOM and what the best practices are.
 

UPDATE: I found some code on how to shift a block of text. Instead of using ".LeftIndent", this is what I used:

[pre]objWrd.ActiveDocument.Paragraphs(18).IndentCharWidth 1[/pre]

This moved the lines of text (showing in the DOM as paragraphs) over to the right about 1.5 characters.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top