[program-l] Re: Changing Document Layout in Word using VBA

  • From: "Ian Sharpe" <isforums@xxxxxxxx>
  • To: <program-l@xxxxxxxxxxxxx>
  • Date: Fri, 9 Oct 2009 16:49:05 +0100

Hi Chris

Apologies if I've missed anything but it's not clear to me what format the
original documents are in? Is it Word format or HTML?

I'd be tempted to convert the document into XML then apply a stylesheet to
it. If the source is Word document you can save as XML so it's easy. You
then would just need to look at the structure of the XML file produced and
it should be relatively straight forward from there.

If the doc is in HTML format, you can run it through HTML TIDY, an open
source utility that will turn HTML documents into XHTML. Then you're back to
simply transforming it to whatever you want.

I know you said that you or at least the tutor, is not able to influence or
change the way the document is layed out, but it maybe possible to actually
get access to the source information, then generate a document in a suitable
layout from the beginning. Obviously not sure of the environment you're
working in but I find that if you approach those responsible for the
document in an open and constructive manner and explain the problem, you may
find they're happy to do what they can and probably weren't awrae of the
issue in the first place. Failing that, throw the DDA at them!! (just
joking!!)

Cheers
ian

-----Original Message-----
From: program-l-bounce@xxxxxxxxxxxxx [mailto:program-l-bounce@xxxxxxxxxxxxx]
On Behalf Of Christopher Edwards
Sent: 08 October 2009 14:45
To: program-l@xxxxxxxxxxxxx
Subject: [program-l] Changing Document Layout in Word using VBA

Hi,

As promised, here is my first question. I am sorry if the message seems
long.

A friend of mine has asked me if I can automate the conversion of a lot of
documents so that they are more easily read by his students using screen
readers. The source of the documents is outside his control and his efforts
to get the layout changed at source have been time consuming and
unsuccessful so far.

Here is a brief description of the situation.

Each document consists of one page.

The layout of the page has been achieved by putting all the text (and one
graphic) inside text boxes.

at the top of the page there is some heading information and there is also a
small amount of information at the bottom of the page.

The middle of the page consists of two columns of five text boxes reading
from top to bottom and then starting at the top of the second column. The
text in each box starts with a number from 1 to 10. These boxes are much
larger than the others.

This is what I have done so far.

I have written code which displays an Open File dialog, opens the selected
file and opens a new document to contain the reformatted text.

I then loop through the text boxes, extract the text, insert a blank line at
the end of the new document and then paste the text after that. Finally, I
save the new document.

This works fine but, although the text from each box is correctly formatted
and in the correct sequence the groups themselves are in an unpredictable
order.

I originally thought this would be all right as my friend is sighted and I
thought it would be quite easy for him to rearrange the text. This is the
case but new documents may come out during the year and the whole lot is
replaced each year. So, I want to try and reduce his workload if I can.

There is nothing unique about the Text Box names and many have the same
name. I am wondering if it would be possible to identify their position and
change this to a sort key which I could write to a collection or array to be
sorted into the correct order before pasting the text into the new document.
I have studied the Help system but have not found anything that seems to
indicate how I might do this so am at the limits of my knowledge.

I have also thought of another method which is rather a brute force
solution. I could loop through the boxes and use the coordinates of each box
to create a sort key which I could use to create and array I can sort. I
could use the dimensions of the boxes to identify the 10 big boxes and the
order they should be in. I could then loop through the sorted array and each
time loop through the text boxes to find the next box to have its contents
pasted into the new document. I could delete the text box once I have pasted
its contents so I don't have to loop through it next time. If I could
interrogate the contents of the text in the text boxes this would help. If I
could identify the number at the beginning of each of the main boxes I could
tell the position where it needed to be placed.However, although I can copy
and pase the text I have found no way to examine it, although I am sure this
must be possible.

This sounds extremely complex and I learned in my days of programming
mainframes many years ago that if things seemed to be getting unduly
complicated I was probably missing something obvious.

If anyone can give me any clues as to what I might be able to do I would be
very grateful. I am using Office XP.

Many thanks,

Chris Edwards



__________ Information from ESET Smart Security, version of virus signature
database 4467 (20090929) __________

The message was checked by ESET Smart Security.

http://www.eset.com



** To leave the list, click on the immediately-following link:-
** [mailto:program-l-request@xxxxxxxxxxxxx?subject=unsubscribe]
** If this link doesn't work then send a message to:
** program-l-request@xxxxxxxxxxxxx
** and in the Subject line type
** unsubscribe
** For other list commands such as vacation mode, click on the
** immediately-following link:-
** [mailto:program-l-request@xxxxxxxxxxxxx?subject=faq]
** or send a message, to
** program-l-request@xxxxxxxxxxxxx with the Subject:- faq

** To leave the list, click on the immediately-following link:-
** [mailto:program-l-request@xxxxxxxxxxxxx?subject=unsubscribe]
** If this link doesn't work then send a message to:
** program-l-request@xxxxxxxxxxxxx
** and in the Subject line type
** unsubscribe
** For other list commands such as vacation mode, click on the
** immediately-following link:-
** [mailto:program-l-request@xxxxxxxxxxxxx?subject=faq]
** or send a message, to
** program-l-request@xxxxxxxxxxxxx with the Subject:- faq

Other related posts: