Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / April 2007

Tip: Looking for answers? Try searching our database.

Drawing lines

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Fuzzhead - 29 Apr 2007 19:08 GMT
I have converted documents from WordPerfect to Word and I am trying to drawn
a line in selected locations. Where ever I have 10 spaces I want to replace
it with no spaces and at that same location draw a line. Below is my macro
but it’s not working. What am I doing wrong?

Dim oFFline As Shape
Dim i
On Error GoTo Endthis
i = Selection.Information(wdVerticalPositionRelativeToPage)

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
   .Text = "          "
   .Replacement.Text = ""
       Set oFFline = ActiveDocument.Shapes.AddLine(554, i + 12, 524, i + 12)
       oFFline.Name = "hline" & idx
       idx = idx + 1
   .Forward = True
   .Wrap = wdFindContinue

Selection.Find.Execute Replace:=wdReplaceAll

Endthis:
Jay Freedman - 29 Apr 2007 20:59 GMT
Besides the syntax error that there's no End With statement to match
your With statement, you can't stick an unrelated action into the
setup of a .Find object and have it work for a ReplaceAll. You have to
change to doing each replacement individually in a While loop, and put
the action (in this case, drawing the line) into that loop.

Another problem is that you never update the variable i (the vertical
position) for each selection; it gets set once wherever the selection
happens to be at the time the macro starts. That, too, has to go into
the loop so it's reevaluated for each Selection location.

I made a few other small patch-ups in the following...

   Dim oFFline As Shape
   Dim i As Long
   Dim idx As Long
   On Error GoTo Endthis
   
   idx = 1
   Selection.HomeKey unit:=wdStory
   
   Selection.Find.ClearFormatting
   Selection.Find.Replacement.ClearFormatting
   With Selection.Find
       .Text = "          "
       .Replacement.Text = ""
       .Format = False
       .Forward = True
       .Wrap = wdFindStop
   End With
   
   'Selection.Find.Execute Replace:=wdReplaceAll
   Do While Selection.Find.Execute(Replace:=wdReplaceOne)
       i = Selection.Information(wdVerticalPositionRelativeToPage)
       Set oFFline = ActiveDocument.Shapes.AddLine(554, i + 12, 524,
i + 12)
       oFFline.Name = "hline" & idx
       idx = idx + 1
   Loop
   
Endthis:

--
Regards,
Jay Freedman
Microsoft Word MVP        FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.

>I have converted documents from WordPerfect to Word and I am trying to drawn
>a line in selected locations. Where ever I have 10 spaces I want to replace
[quoted text clipped - 20 lines]
>
>Endthis:
Fuzzhead - 29 Apr 2007 23:34 GMT
Hi Jay,

Thank you from your help. The macro worked perfectly.

Fuzzhead

> Besides the syntax error that there's no End With statement to match
> your With statement, you can't stick an unrelated action into the
[quoted text clipped - 69 lines]
> >
> >Endthis:

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.