Drawing a line

P

Patrick Pirtle

Well, I've gotten close. I'm trying to draw a line a specific
distance to the left of the beginning of the current paragraph.
The code below works in my test document, but in the
actual working document, all it does is move the selection to
the beginning of the line of text--it never draws the graphic
line.


Sub test()
Dim xLoc As Integer
Dim yLoc As Integer
Selection.MoveStart wdLine
Selection.MoveUp wdLine
xLoc = Selection.Information(wdHorizontalPositionRelativeToPage)
yLoc = Selection.Information(wdVerticalPositionRelativeToPage)

With ActiveDocument.Shapes.AddLine(xLoc - 25, yLoc, xLoc - 25, yLoc +
15).Line
.EndArrowheadStyle = msoArrowheadDiamond
.BeginArrowheadStyle = msoArrowheadDiamond
.ForeColor = RGB(0, 128, 0)
End With


Any suggestions? TIA for your help.

____________________________________________
The impossible just takes a little longer...
 
L

Lene Fredborg

I tried running your macro and a line was added.

Things you could check:

Do you view your document in Normal view? The line you add is an AutoShape.
AutoShapes are not visible in Normal view.

If the line is inserted in left-aligned text, the line is added in the left
margin. If you have a very narrow left margin, the line could be outside the
page.

Also, Tools > Options > View tab > Drawings must be turned on (however, this
is not likely to be the problem since you can see the line in your test
document - and the setting applies to all documents).

--
Regards
Lene Fredborg
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word
 
P

Patrick Pirtle

Lene -
Thank you for your reply.


I'm viewing the document in "Print Layout" view. I
can manually draw a line, and it displays.


I tried :

With ActiveDocument.Shapes.AddLine(xLoc, yLoc, xLoc, yLoc + 25).Line

so the line would be drawn beginning directly at my current
location, but it made no difference.



This is checked on.


____________________________________________
The impossible just takes a little longer...




Lene said:
I tried running your macro and a line was added.
[snip]
 
R

Russ

Inline reply
[snip]
This is checked on.
You could add this to the top of your macro(after dimensioning variables) to
be sure that conditions are right for drawing:

ActiveWindow.View.Type = wdPageView
ActiveWindow.View.ShowDrawings = True

Just before End Sub add this line to be in print preview, if that is what
you want.

ActiveWindow.View.Type = wdPrintPreview
 
P

Patrick Pirtle

Russ -
Thanks for your reply. I put those two lines in at the
beginning of my sub, but the line doesn't show up.
However, I can manually draw lines and they show
up just fine. And my sub works fine in other documents.
So, there must be some setting that's preventing these
lines from showing up in this one document. Weird,
huh?

Here's my entire sub:


Sub test()
Dim xLoc As Integer
Dim yLoc As Integer

ActiveWindow.View.Type = wdPageView
ActiveWindow.View.ShowDrawings = True

Selection.MoveStart unit:=wdLine
Selection.MoveUp wdLine

xLoc = Selection.Information(wdHorizontalPositionRelativeToPage)
yLoc = Selection.Information(wdVerticalPositionRelativeToPage)

With ActiveDocument.Shapes.AddLine(xLoc, yLoc, xLoc, yLoc + 25).Line
.EndArrowheadStyle = msoArrowheadDiamond
.BeginArrowheadStyle = msoArrowheadDiamond
.ForeColor = RGB(0, 128, 0)
End With
End Sub


____________________________________________
The impossible just takes a little longer...
Inline reply
[snip]
This is checked on.
You could add this to the top of your macro(after dimensioning
variables) to be sure that conditions are right for drawing:

ActiveWindow.View.Type = wdPageView
ActiveWindow.View.ShowDrawings = True

Just before End Sub add this line to be in print preview, if that is
what you want.

ActiveWindow.View.Type = wdPrintPreview

--
 
P

Patrick Pirtle

Problem Solved--I added the following line:

.Visible = msoTrue

in the "With" block, and my lines started showing up. So
now my question is...Where do I change the setting so
that lines automatically display? TIA for any help and
suggestions.
____________________________________________
The impossible just takes a little longer...

Russ -
Thanks for your reply. I put those two lines in at the
beginning of my sub, but the line doesn't show up.
However, I can manually draw lines and they show
up just fine. And my sub works fine in other documents.
So, there must be some setting that's preventing these
lines from showing up in this one document. Weird,
huh?

Here's my entire sub:


Sub test()
Dim xLoc As Integer
Dim yLoc As Integer

ActiveWindow.View.Type = wdPageView
ActiveWindow.View.ShowDrawings = True

Selection.MoveStart unit:=wdLine
Selection.MoveUp wdLine

xLoc = Selection.Information(wdHorizontalPositionRelativeToPage)
yLoc = Selection.Information(wdVerticalPositionRelativeToPage)

With ActiveDocument.Shapes.AddLine(xLoc, yLoc, xLoc, yLoc +
25).Line .EndArrowheadStyle = msoArrowheadDiamond
.BeginArrowheadStyle = msoArrowheadDiamond
.ForeColor = RGB(0, 128, 0)
End With
End Sub


____________________________________________
The impossible just takes a little longer...
Inline reply
[snip]
Also, Tools > Options > View tab > Drawings must be turned on
(however, this is not likely to be the problem since you can see
the line in your test document - and the setting applies to all
documents).

This is checked on.
You could add this to the top of your macro(after dimensioning
variables) to be sure that conditions are right for drawing:

ActiveWindow.View.Type = wdPageView
ActiveWindow.View.ShowDrawings = True

Just before End Sub add this line to be in print preview, if that is
what you want.

ActiveWindow.View.Type = wdPrintPreview

--
 
R

Russ

Patrick,
I was able to manually recreate your circumstances.
I created a double-arrowheaded line. It was Visible.
In the toolbar 'Pick a color' button for the line I selected the box that
said "no line". The line disappeared.
I then selected the button in the main toolbar that said 'Set AutoShape
Defaults'.
Next I tried to create another line.
It was invisible.

Therefore,
Select a autoshape, select 'automatic or black' for color, and select 'Set
AutoShape Defaults' to get things back to normal in your Word.

You could record a macro while doing this stuff to make sure that the
defaults were always set to visible where ever your macro is run, but as you
discovered the '.Visible = msoTrue' will suffice in the macro.
Problem Solved--I added the following line:

.Visible = msoTrue

in the "With" block, and my lines started showing up. So
now my question is...Where do I change the setting so
that lines automatically display? TIA for any help and
suggestions.
____________________________________________
The impossible just takes a little longer...

Russ -
Thanks for your reply. I put those two lines in at the
beginning of my sub, but the line doesn't show up.
However, I can manually draw lines and they show
up just fine. And my sub works fine in other documents.
So, there must be some setting that's preventing these
lines from showing up in this one document. Weird,
huh?

Here's my entire sub:


Sub test()
Dim xLoc As Integer
Dim yLoc As Integer

ActiveWindow.View.Type = wdPageView
ActiveWindow.View.ShowDrawings = True

Selection.MoveStart unit:=wdLine
Selection.MoveUp wdLine

xLoc = Selection.Information(wdHorizontalPositionRelativeToPage)
yLoc = Selection.Information(wdVerticalPositionRelativeToPage)

With ActiveDocument.Shapes.AddLine(xLoc, yLoc, xLoc, yLoc +
25).Line .EndArrowheadStyle = msoArrowheadDiamond
.BeginArrowheadStyle = msoArrowheadDiamond
.ForeColor = RGB(0, 128, 0)
End With
End Sub


____________________________________________
The impossible just takes a little longer...
Inline reply
[snip]
Also, Tools > Options > View tab > Drawings must be turned on
(however, this is not likely to be the problem since you can see
the line in your test document - and the setting applies to all
documents).

This is checked on.
You could add this to the top of your macro(after dimensioning
variables) to be sure that conditions are right for drawing:

ActiveWindow.View.Type = wdPageView
ActiveWindow.View.ShowDrawings = True

Just before End Sub add this line to be in print preview, if that is
what you want.

ActiveWindow.View.Type = wdPrintPreview
 
P

Patrick Pirtle

Ah. Many thanks for your reply! Works like a charm.

____________________________________________
The impossible just takes a little longer...

Patrick,
I was able to manually recreate your circumstances.
I created a double-arrowheaded line. It was Visible.
In the toolbar 'Pick a color' button for the line I selected the box
that said "no line". The line disappeared.
I then selected the button in the main toolbar that said 'Set
AutoShape Defaults'.
Next I tried to create another line.
It was invisible.

Therefore,
Select a autoshape, select 'automatic or black' for color, and select
'Set AutoShape Defaults' to get things back to normal in your Word.
[snip]
 

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