PDA

View Full Version : Remove frames without removing formatting



quicksilver7
05-27-2008, 12:01 PM
Hi all,

A custom program exports letters using Crystal into Word .doc format but all the text is encased in frames. I have been asked to create a macro so that users can remove all the frames in a document. Currently, if all the text within a frame is deleted and the frame removed, the space that the fame occupied remains, and there appears to be no way to select or delete it. :banghead:

When attempting to remove a frame manually with the text still inside, the text moves to another part of the page, usually at or near the top, sometimes left but sometimes right justified. :motz2:

An example letter with the frames is attached.

Is there a way in VBA to remove these frames without affecting the underlying text (i.e. so the text retains its position in the document)?

Thanks,

Dave

gwkenny
05-27-2008, 12:39 PM
The short answer to your question is that you need someone to redesign your crystal report output. Unfortunately I have no direct experience with crystal reports, but I have seen output generated into RTF format that didn't have all those frames that was supposed to have been generated by crystal reports. So there might be a clue in utilizing RTF format, but I'm not really the right person to ask.

Long Answer to your questions. There is no easy way to convert your letter that you have with all the text in individual frames into a "standard" word type doc easily.

I can explain though what you are seeing when you manipulate frames.

Word is based on character, paragraph marks and section breaks. Any aspect of a document is embedded in either the character, paragraph mark, and/or section break. Frames are no different. Frames are embedded within the paragraph mark they are anchored too. When you remove a frame, the text jumps to the paragraph mark the frame was anchored too.

When you remove all the text within the Frame and the last paragraph mark is in standard "normal" style, then the justification for the frame's existence is gone and it is removed. The reason you still have a "space" in your document is because all the other text are in frames too. And those frames are anchored to the first few paragraph marks at the top of your document, so they do not move.

Wish I had a better answer.

fumei
05-27-2008, 01:27 PM
Based on your sample document, then the answer to:

"Is there a way in VBA to remove these frames without affecting the underlying text (i.e. so the text retains its position in the document)?"

is, simply put, no.

If it is at all possible, I would agree with gw that the best route is to try and get a different output, likely RFT.

The document sample would be impossible to make a "normal" Word document. Well, not impossible, but extremely difficult. Even the "line":

b) a copy of the minutes of the public meeting;

is actually TWO, separate Frames. The b) is one, the text is in another.

You CAN create a new document, without the frames, but your format and positioning would be lost.

Dim ThisDoc As Document
Dim ThatDoc As Document
Dim objFrame As Frame
Dim strFrameText As String

Set ThisDoc = ActiveDocument
Set ThatDoc = Documents.Add

For Each objFrame In ThisDoc.Frames
strFrameText = objFrame.Range.Text
ThatDoc.Range.InsertAfter strFrameText & vbCrLf
Next

Regarding the separate frames, this produces the result of:

b)

a copy of the minutes of the public meeting;


Also, notice that the text in the paragraphs have each line terminated by a paragraph mark. That is, a paragraph mark is used to explicitly terminate a line, rather than let Word use word wrapping.

Now, if you always had the same number of frames, it is possible to figure out the logic of the frame count number to format/structure. Then extrapolate from there.

frame#7 = "RE:"
frame#8 = "Application for Approval of a Plan of Condominium" (or whatever text would be in frame #8

However, I doubt if this is realistic. For one thing, File Number and Cross Reference (the text) are in ONE frame. The file number itself is in a separate frame. I would assume that if there was a Cross Reference number it would be in the same frame as the file number - just like "Cross Reference" is in the same frame as "File Number".

That means you would have to do serious logic testing of strings. Like:

If the second paragraph of frame#9 text string is not blank (i.e there IS a cross reference number), then...split the text into two paragraphs - the first one to match File Number, the second to match Cross Reference.

A full blown nightmare. Is it possible? Yes, it would be possible. However, is it reasonable? No. It would take a great deal of work, extremely careful error trapping, and most likely NOT worth the development time.

fumei
05-27-2008, 01:28 PM
ps. I hate frames.

Crooz
05-28-2008, 05:05 AM
Hi Dave,
Try this in your Word document:
Ctrl+A
Ctrl+Q

quicksilver7
05-28-2008, 08:44 AM
Thank you gwkenny, fumei, and Crooz, for your replies. I got one of the users to export a letter as a RTF file, but the frames persisted in the same manner as with a .doc export.

The custom program is an extension to the GIS software, ArcGIS, which includes the bare bones runtime DLL of Crystal Reports with the install. The Crystal interface allows a report to be exported into a variety of formats, including Word .doc's, .rtf's, pdf's, and plain text files. I suspect that these annoying frames are Crystal's way of frustrating users into buying the full-blown version of its software. In 2000, I wrote code using the Crystal Report object within a VB project, and it was a pain in the a$$; perhaps the newer version would be less so? : pray2:

gwkenny, thanks for the explanation of the paragraph marks, etc. Crooz and fumei, I tried your suggestions with similar results: the text remains and the paragraphs retain their positions relative to each other, but all tab indentation and empty lines are gone. It's at times like these that I miss the old WordStar, with its simple view codes feature, which displayed all the formatting tags alongside the text.

fumei, you're right, to try to code for this would be a nightmare, especially since the number of frames would vary. For instance, I was given one example where the recipient's address had a PO Box on one line and a street address on another while another example had just the street address.

Any other suggestions anyone?

Thanks,

Dave

fumei
05-28-2008, 12:35 PM
Crooz, did you actually try using Ctrl-A / Ctrl-Q on the document posted?

quicksilver7
06-04-2008, 02:07 PM
Okay fumei, I have taken your code sample and started to place a series of conditions within the loop in an attempt to position the text in a manner that is close to the original. It would be nice if I could just farm this out to somebody in this forum who knows what they're doing, but no, we're a local government body, and cannot do that without a long, involved process.

Anyway, I'm stuck with this Range object. The examples on the MSDN site are pathetic, assuming one can set the instance of the object variable by referring to a start and end character or paragraph position. I want to do it with a search for a particular text string. Is it possible? Thanks,

Dave

Set rngFileNum = ThatDoc.Range(ThatDoc.Range.Find("File Number"))