Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 650
  • Last Modified:

find page break and the column where I am in word VBA

Hi...
I am generating a word document using VBA.

The document is in the format of two columns every page.

The data should fill the first column till the end of the first page and then should fill the second column till the end of the first page and then should go to the first column of the second page and then second column in the second page.......like that..

Here I need to locate the page break(when I reach the end of every page) and the column where I am(either in the first column or second column)...so that...the data can traverse as said above...

can anyone help me in this.
0
amiteshsinha
Asked:
amiteshsinha
  • 6
  • 5
  • 3
2 Solutions
 
GrahamSkanCommented:
It should be all automatic. Just select the text and go to Format/Columns and choose Two.
Columns like that are sometimes called 'snaking columns'
0
 
GrahamSkanCommented:
Sorry, just seen the VBA bit.
0
 
GrahamSkanCommented:
This will do it in VBA
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
GrahamSkanCommented:
Sorry, I mean this:
It will do the first section only.
Sub TwoCols()
    With ActiveDocument.Sections(1).PageSetup.TextColumns
        .SetCount NumColumns:=2
        .EvenlySpaced = True
        .LineBetween = False
        .Width = CentimetersToPoints(6.7)
        .Spacing = CentimetersToPoints(1.25)
    End With
End Sub

To do the whole document, change th With line to this:
   With ActiveDocument.PageSetup.TextColumns

0
 
amiteshsinhaAuthor Commented:
Hi...I've already added table/columns...I need answer for this....

***************
Here I need to locate the page break(when I reach the end of every page) and the column where I am(either in the first column or second column)...so that...the data can traverse as said above...
****************
0
 
AntonioPCommented:
How are you generating this document? Can you describe your VBA a little?  I don't understand why the data is not snaking through the columns automatically.
0
 
amiteshsinhaAuthor Commented:
I am getting the data dynamically and putting it in the first column of the table like this...

with wrdApp.Selection
        .Tables.Add wrdApp.Selection.Range, NumRows:=1, NumColumns:=2
        .MoveLeft unit:=wdCell

        .TypeParagraph
        .TypeText Text:="Feature ONE"
     
        .TypeParagraph
        .TypeText Text:="Bullet One"

        .TypeParagraph
        .TypeText Text:="Bullet Two"

        .TypeParagraph
        .TypeText Text:="Feature TWO"
     
        .TypeParagraph
        .TypeText Text:="Bullet One"

        .TypeParagraph
        .TypeText Text:="Bullet Two"


and when the end of the page comes..it should go to the next(second) column of the table in the same page. It should not go to the first column of the second page. Likewise when it is done with the second column of the first page, the cursor should go to the first column of the second page.

I am using
.MoveRight unit:=wdCell
.MoveLeft unit:=wdCell

to move the cursor from first column to second column and vice versa. But I am not able to find when the soft page break occurs and in which column I am(either in the first or second) to move the cursor accordingly.

Hope I am clear...if not pls. question me...
0
 
amiteshsinhaAuthor Commented:
Any answers????
0
 
AntonioPCommented:
You're using tables?  That changes everything; I thought you just were using column formatting for free text.

I'm afraid I never use Word tables, but hopefully someone better than I can take this question further. Good Luck!
0
 
amiteshsinhaAuthor Commented:
HI AntonioP

Is thr any way where I can achieve the format I want without using tables??
0
 
AntonioPCommented:
Well, if I understand the code (which I may not), you're creating a table that consists of 1 row and two columns, going to the left cell, and filling it with text.  And you want for that text to fill the left cell until the end of the page, then move to the right cell and start filling that to the end of the page, then move to the next page.

If so, this is exactly what Word's column formatting is for.  Start with a new document, use the code that GrahamSkan supplied, and then just start blasting the text into the document.  You may need to experiment a bit with the column widths, etc., to give you the formatting you want, but you should be all set.  Also, you may want to format each group with

    Selection.ParagraphFormat.KeepTogether = True

so that you do not have the feature name ending up on one page and the bullets on the next.

If you want to see how the column formatting works before you start re-writing your code, just make a new document,
use Format>Columns to make it two columns, and type in "=rand(20,4)" and hit return.
0
 
amiteshsinhaAuthor Commented:
Wow...this is what I was looking for. Thanks a loooot...

0
 
amiteshsinhaAuthor Commented:
Hi..

In this same issue I have one more clarification.
In a single page how to make one TextColumns count as 1 and another TextColumns count as 2...??
Let me know if I've to post this as a diff. issue.
0
 
GrahamSkanCommented:
It would be a good idea to post another question, but I will tell you now that I don't understand what your new requirement.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 6
  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now