Solved

Word - Visual Basic code

Posted on 2011-03-20
12
355 Views
Last Modified: 2012-05-11
I am trying to do a mail merge to print addresses into a document.  Each address block would be a record by itself, because the paper size will be 8.5 x 8.5.
Once the addresses have been merged into a document and then saved.
I would like to open this document and then run a code that will invert the whole address block, and then go to the next address block and do the same until EOF.
For instance, an address could be as in the document attached, and then please see how the inverted address would like.  
To make coding easier, I could put a delimited for the start of the address, and another one at the end of the address block, but when inverting the address, these delimiters have to be excluded.
Can someone please  suggest some solutions for this project.  I have tried twidling with the Printer drivers and also examining the printer menu on the printer, but there is nothing that could do this, because the Xerox 4500 Printer that I have is not an envelope printer.  in some envelope printers like Pitney Bowes I think have the feature of feeding the mail piece bottoms up and then printing the address inverted.  This is because the other end of the mail piece has open flaps that would jam the printer. thank u for your inputs.
Another thought I have is, from Access when it prints the address line by liine, to print it inverted.
Thus an address line like
   John Doe
would print as :
   eoD nhoJ
is this a workable solution for this inverted printing?
Sorry I forgot, I use Windows 7 and Microsoft Word 2007 and the data file will be from Access 2007.
upsidedown.docx
0
Comment
Question by:jegajothy
  • 3
  • 3
  • 3
  • +2
12 Comments
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 35175757
From your sample, it looks like you will be "Folding" this paper..?

If so, then consider running it through the printer twice.
Once "Flat", then Folded.

In other words set the "Printout" to be the same, then just fold/reorient the paper, ...and print it through again.

This should same you all the jerking around with trying to "Invert" the text

Just a suggestion...

Let's see what some other Experts post...

JeffCoachman
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 35176034
You could put the text and mergefields in two side-by side text boxes, with the text direction running upwards in one and downwards in the other.
0
 

Expert Comment

by:13cactus
ID: 35176130
I think the easiest would be like this:

1. Set the page orientation to landscape
2. Add a table with one row and two columns spanning the page (in height and width)
3. Set the text direction on the left cell bottom to top
4. Set the text direction on the left call top to bottom
5. Add the merge fields and layout in the left and right column

Please see attached document for an example.
example.doc
0
 
LVL 33

Expert Comment

by:Norie
ID: 35176231
How about doing it side by side?

Then you could use a table with 2 cells for each address and set the rotation in one of the cells to 180.

I came up with this but I'm not sure it's anywhere near what you want.

Try it on a document with just the address which has been bookmarked as 'Address1'.
Option Explicit

Sub Macro1()
Dim tbl As Table
Dim celLH As Cell
Dim celRH As Cell

    Set tbl = ActiveDocument.Tables.Add(ActiveDocument.Bookmarks("\EndOfDoc").Range, 1, 2)
    
    Set celLH = tbl.Cell(1, 1)
    
    celLH.Range.Text = ActiveDocument.Bookmarks("Address1").Range.Text
    
    celLH.Range.Orientation = wdTextOrientationDownward
    Set celRH = tbl.Cell(1, 2)
    
    celRH.Range.Text = ActiveDocument.Bookmarks("Address1").Range.Text
    
    celRH.Range.Orientation = wdTextOrientationUpward
    
    tbl.AutoFitBehavior wdAutoFitContent
    
 End Sub

Open in new window

0
 

Author Comment

by:jegajothy
ID: 35180359
in response to imiorie, I got a runtime error.  This is what I did, I created a 3 row table of one column.
Then I inserted the address one line per row.
and then I ran your macro, and I got a runtime 5941 error, sometthing like collection does not exist at the following line when i debugged it :
    celLH.Range.Text = ActiveDocument.Bookmarks("Address1").Range.Text
Being a novice, I have no clue how to fix this error.  Hope u can help. thank u.
0
 

Author Comment

by:jegajothy
ID: 35180413
in response to 13cactus, your sample doc shows the result.  But I am lost of how u achieved it.  Do you think u could please give me a step by step instruction.  thank u.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 33

Expert Comment

by:Norie
ID: 35180667
Don't create a table, just type in one address, select it and bookmark it with the name 'Address1'.

Now run the code.

It should create a table with the address shown twice side by side but aligned 'downwards' in the left cell and 'upwards' in the right cell.

Actually you should probably go with 13cactus' idea which you should be able to do without code.

I'm not exactly sure how it's been done, not downloaded the file yet, but I know there is a way to repeat merge fields.

I think that's probably one of the things you need to do, ie repeat the address
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 35181374
Have you tried the textboxes suggestion? It doesn't need any code, because you lay it out in the Main merge main form.
Here is an example
 
Textboxes.docx
0
 

Author Comment

by:jegajothy
ID: 35181894
thank u everyone, I tried imnorie's suggestion, but the result is not what I expected.  This is what I did, I typed a single address.  Then highlighted it and inserted a bookmark called Address1.  Then I ran the code, please see attached file I got.   Upside-down-result.docx
0
 
LVL 33

Accepted Solution

by:
Norie earned 500 total points
ID: 35182894
Here's a picture of what my code created using the workbook you attached.

All I did was remove the existing table as the code I posted creates a table.


WordTable.JPG
0
 

Expert Comment

by:13cactus
ID: 35182902
in response to 13cactus, your sample doc shows the result.  But I am lost of how u achieved it.  Do you think u could please give me a step by step instruction.  thank u.

Did you look at the post that contained my attachment? There is a instruction in there how I did it. Unfortunately I seem to use an older version of Office so I can not give you a step by step instruction with the proper menus and options, but I think you should be able to start with the instructions given earlier:

1. Set the page orientation to landscape
2. Add a table with one row and two columns spanning the page (in height and width)
3. Set the text direction on the left cell bottom to top
4. Set the text direction on the left call top to bottom
5. Add the merge fields and layout in the left and right column
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 35183470
Sorry that your question is now extremely confusing. However, I will add a couple of comments. If you wanted to use tables instead of text boxes, it would be best to have two tables side-by side, otherwise you would have to predict the fold very accurately.

Also, your paper format is square, so it isn't easy to see what difference the orientation (landscape or portrait) would make. However, since you are concerned with printer feeding, it might be worth-while experimenting.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

The Selection object is designed for user interaction. It has a Range property, so it can be used in most places that a Range object can. Recorded macros must use the Selection because they are simply copying what the user is doing. A Range prope…
Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
In a previous video Micro Tutorial here at Experts Exchange (http://www.experts-exchange.com/videos/1358/How-to-get-a-free-trial-of-Office-365-with-the-Office-2016-desktop-applications.html), I explained how to get a free, one-month trial of Office …

707 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

12 Experts available now in Live!

Get 1:1 Help Now