Solved

VBA / MS Word problem

Posted on 2006-10-23
3
382 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

758 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

21 Experts available now in Live!

Get 1:1 Help Now