Solved

VBA / MS Word problem

Posted on 2006-10-23
3
388 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…
Suggested Courses
Course of the Month8 days, 18 hours left to enroll

615 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