Insert Line At Exact Location

D

Derek Hart

In a word document, I need to insert horizonal lines at exact locations in
VBA. This is for a pitney bowes folding system, where it reads the exact
position of the lines to automatically fold and mail documents. I will know
ahead of time the exact positions of up to 5 of these lines on the bottom
right margin. In VBA can I add a horizonal line graphic at an exact
location that will not move at all. I could possibly place these lines in
the document ahead of time, and just make them visible or not. Any thoughts
on a good way to do this would be appreciated. Sample code would be great.

Thank You!
Derek Hart
 
D

Doug Robbins - Word MVP

I assume that you are talking about short lines in the lefthand margin. The
best way to do that would be to use the Header of the template to insert
them. Then their position will not be affected by the text in the body of
the document.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
D

Derek Hart

I need to know in VBA code how to insert horizontal lines at exact locations
in the right (lower part of the page) margin of the document. Should I
increase the size of the footer and place it in the footer? Can you be more
specific about how to do this?

Thank You,
Derek Hart
 
D

Doug Robbins - Word MVP

I would not try and do it with VBA. Rather, create a template to be used as
the basis for the documents and set the lines up in the template.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
D

Derek Hart

OK, I will need to read information from SQL Server to know when and where
to turn on up to 5 of these lines on a page. I have to do this
programtically. So I need to either place all 5 there and make them visible
or not, or add them in code. If I do it the first way, I need to name the
lines so I can reference them in code. Any ideas?
 
D

Doug Robbins - Word MVP

Sorry, I am out of my depth. Maybe there is some Pitney Bowes support forum
where you could get assistance.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
J

Jean-Guy Marcil

Derek Hart was telling us:
Derek Hart nous racontait que :
OK, I will need to read information from SQL Server to know when and
where to turn on up to 5 of these lines on a page. I have to do this
programtically. So I need to either place all 5 there and make them
visible or not, or add them in code. If I do it the first way, I
need to name the lines so I can reference them in code. Any ideas?

Try this:

'_______________________________________
Sub NameLines()

Selection.ShapeRange(1).Name = "Line1"

End Sub
'_______________________________________

'_______________________________________
Sub ChangeLineVisibility()

Dim myShape As Shape

With ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary)
For Each myShape In .Shapes
With myShape
If InStr(1, .Name, "Line") > 0 Then
.Line.Visible = Not .Line.Visible
End If
End With
Next

End With

End Sub
'_______________________________________

Insert the lines manually in the template, in the main footer in section 1.
Select the first one and run the NameLines macro.
Then change "Line1" to "Line2", select the second line and run the macro
again.
So on until you have named all five line from Line1 to Line5.

Then close the footer and run the second macro to alternatively display/hide
the lines.

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
C

Cindy M -WordMVP-

Hi Derek,
I need to know in VBA code how to insert horizontal lines at exact locations
in the right (lower part of the page) margin of the document. Should I
increase the size of the footer and place it in the footer? Can you be more
specific about how to do this?
The better place for VBA questions is a word.vba newsgroup. You're more likely
to encounter a wide range of people with programming experience there.

You should certainly be able to insert lines using VBA, as you describe.
Whether they should be in the footer depends on whether they should appear on
ALL pages?

If the answer is yes, you don't need to increase the size of the footer.
Graphical objects you insert while in the footer "storyrange" can be anywhere
on the page.

In order to get a feel, and the basic syntax, for positioning the lines, draw a
line of the type you want, then right-click and go into the "Format [object]"
dialog box. Layout/Advanced/Picture position. Note how you can position a
graphical object either relative to the text or to the page. One "Alignment"
option is Right, relative to the page, for example.

Once you're pretty sure what you want, record creating these settings in a
macro to get the basic syntax. You'll probably still need to "tweak" the
result, but at least you'll have a head start, plus the objects involved so
that you can research the Help files.
I will need to read information from SQL Server to know when and where
to turn on up to 5 of these lines on a page. I have to do this
programtically. So I need to either place all 5 there and make them visible
or not, or add them in code. If I do it the first way, I need to name the
lines so I can reference them in code.
A Drawing object is a member of the SHAPES collection. Using VBA code, you can
assign any Shape a NAME (Name property). This is also an Index you can use to
later address the shape (Shapes("Name")).

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 
D

Derek Hart

Thank you for the post. This helps so much. One more question. I need to
place the lines in the middle of the page in the right margin. How do I
place these in the footer when the footer is at the bottom. Are there
settings for the footer to increase the height, and can this overlap normal
paragraphs in the body of the document?

Thank You,
Derek Hart
 
S

Suzanne S. Barnhill

Wrapped objects anchored to the header or footer paragraph can appear
anywhere on the page. They do not affect the size of the header/footer.
 
J

Jay Freedman

Hi Derek,

In case it seems like everyone's talking Greek around you, here's the
translation:

Every graphic can be either "in line with text" or "wrapped" (also
called "floating"). When the graphic is selected, the Text Wrapping
button on the Picture toolbar lets you select which wrapping type you
want -- Square, Top and Bottom, In Front of Text, Behind Text, etc.
You probably should use In Front of Text or Behind Text to avoid
displacing any text.

Every graphic that's wrapped is "anchored" to some text paragraph.
Initially, that's the paragraph that contains the cursor at the time
the graphic is inserted. If the cursor is in the header or footer when
you draw the graphic, the anchor will be in the header or footer,
which means the graphic will repeat on every page just as the header
or footer does.

However, because it's floating, the graphic can be drawn at (or
dragged to) any position on the page. It doesn't have to be inside the
dashed box that shows the header or footer area.

To refine the graphic's position, right-click it and choose Format
AutoShape (or click the Format button on the Picture toolbar). Click
the Layout tab in the dialog and click the Advanced button there. In
the next dialog, under "Horizontal", click Alignment and choose Right
relative to Page. Under "Vertical", click "Absolute position" and set
a measurement (for example, 10.35") below Page.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top