General discussion

Locked

Word Macro

By byron.gough ·
When exporting a crystal report as a Word document, it is next to impossible to edit the new document because all text is placed in frames. I found the following macro that would delete the frames:

Sub CleanUpExport()
For Each aFrame In ActiveDocument.Frames
aFrame.Delete
Next aFrame
End Sub

This macro deletes the frames no problem. Unfortunately, it also deletes all the formatting and the text all becomes left aligned. Has anyone created a macro that could be used to delete the frames AND retain the position/formatting of the text?

I found another macro that seems capable of this but only if the document has text boxes, not frames. I tried to modify this to address my situation but I don't know enough vba.

Sub RemoveTextBox2()
Dim shp As Shape
Dim oRngAnchor As Range
Dim sString As String

For Each shp In ActiveDocument.Shapes
If shp.Type = msoTextBox Then
' copy text to string, without last paragraph mark
sString = Left(shp.TextFrame.TextRange.Text, _
shp.TextFrame.TextRange.Characters.Count - 1)
If Len(sString) > 0 Then
' set the range to insert the text
Set oRngAnchor = shp.Anchor.Paragraphs(1).Range
' insert the textbox text before the range object
oRngAnchor.InsertBefore _
"Textbox start << " & sString & " >> Textbox end"
End If
shp.delete
End If
Next shp
End Sub

I have tried exporting to a number of formats but the only one that even comes close to allowing some editing is Excel. It is just not very nice looking. Any ideas? Thanks for your time,
pfeller

This conversation is currently closed to new comments.

3 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

Did you find a solution?

by jpond In reply to Word Macro

We are experiencing the same problem. we used ot export reports from Crystal 8.5 to Word and they were easily edited now with all the text boxes and frames it is almost impossible. Did you find a way around this?

Jan

Collapse -

Solution

by sreenivaskk In reply to Word Macro

We are facing same problem. Is there any solution remove the frames and keeping the same format. Please let me know.

Collapse -

by rbene In reply to Solution

I found no loss of formatting in the Word document -- the frames are gone, formatting remains. But I'm not working with Crystal, so my initial document was built differently, I'm sure.

What I am experiencing is a loss of tables in the text frames (I have both frames and text frames). Is there any code that would check to see if the content of the text box is a table and if so, copy it out as is?

Good luck with your VBA coding, and thanks.

Back to Software Forum
3 total posts (Page 1 of 1)  

Related Discussions

Related Forums