Solved

VBA / MS Word problem

Posted on 2006-10-23
3
383 Views
Last Modified: 2008-02-01
Hi

Hope someone can help me...

I have a collection (named PointsCollection) of X and Y values that I use to draw rectangle shapes on a word document (named Doc).

X and Y are the left and top values for each rectangle, relatives to the page.

For each Point in PointsCollection

   Set Shp = Doc.Shapes.AddShape( msoShapeRectangle, Point.X, Point.Y, 50, 50 )

next

This works fine but I must only print a maximum of 3 rectangles on each page. If there are any more rectangles then I must add a new pages and start adding the remaining rectangles there.

How can I do this?
0
Comment
Question by:rettiseert
3 Comments
 
LVL 26

Expert Comment

by:EDDYKT
ID: 17794951

dim i as integer


For each Point in PointsCollection

   i = i + 1
   Set Shp = Doc.Shapes.AddShape( msoShapeRectangle, Point.X, Point.Y, 50, 50 )
   if (i = 3) then
       Application.Selection.InsertBreak Type:=wdPageBreak
        i= 0
    end if
next


where application is your word.application
0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 total points
ID: 17794967
You need to use the Anchor parameter. Put page breaks in and then a paragraph to tie the shapes to.

Option Explicit

Sub InsertShapes(Doc as Word.Document)
    Dim shp As Shape
    Dim p As Word.Paragraph
    Dim t As Integer

    Set p = Doc.Paragraphs.Add(Doc.Bookmarks("\StartOfDoc").Range)
    Set shp = Doc.Shapes.AddShape(msoShapeRectangle, 10, 10, 50, 50, p.Range)
    For t = 2 To 10
        Doc.Bookmarks("\EndOfDoc").Range.InsertBreak wdPageBreak
        Doc.Bookmarks("\EndOfDoc").Range.InsertParagraph
        Set p = Doc.Paragraphs.Last
    Set shp = Doc.Shapes.AddShape(msoShapeRectangle, 10 * t, 10, 50, 50, p.Range)
    Next t
End Sub

0
 
LVL 13

Author Comment

by:rettiseert
ID: 17796053
Hello EDDYKT , I have already tested your suggestion, if you run the code you'll find that it doesn't works as spected


Hi GrahamSkan, thanks!, I think I can work using your suggestion!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

947 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now