1 Attachment(s)
Word formatting problems -TabStops & TypeText
An existing VB6 app uses Word automation to create/print reports. The posted code is a small snippet of the whole process but the majority of the code uses the these same Word methods/properties.
The first 3 lines of the attached picture are what normally gets created/printed. The bottom 3 lines are what is happening to 1 user but not all the time. The TypeText method is printing all the text in the same position. Sometimes closing/opening the app solves the problem but in some cases a re-boot is necessary.
I don't know much about Word and need some suggestions on how to begin to troubleshoot this problem.
Thanks.
Code:
With wdApp
.Selection.ParagraphFormat.TabStops.Add Position:=.InchesToPoints(4.25), Alignment:=wdAlignTabLeft, Leader:=wdTabLeaderSpaces
.Selection.ParagraphFormat.TabStops.Add Position:=.InchesToPoints(5), Alignment:=wdAlignTabLeft, Leader:=wdTabLeaderSpaces
.Selection.TypeText Text:="B.C. CORONERS SERVICE" & vbTab & "TOXICOLOGY REPORT"
.Selection.TypeParagraph
.Selection.TypeParagraph
.Selection.ParagraphFormat.TabStops.Add Position:=.InchesToPoints(1.5), Alignment:=wdAlignTabLeft, Leader:=wdTabLeaderSpaces
.Selection.TypeText Text:="PTC No:" & vbTab
.Selection.Font.Bold = wdToggle
.Selection.TypeText Text:= Format(rs!Case_PTC_No, "####-####")
.Selection.Font.Bold = wdToggle
.Selection.TypeParagraph
.Selection.TypeParagraph
.Selection.TypeText Text:="The results are as follows: (* indicates new result)"
.Selection.TypeParagraph
.Selection.TypeParagraph
Re: Word formatting problems -TabStops & TypeText
i would avoid working with the selection object, better to work with a specific range, but i doubt that has any bearing on your problem
what is the next few lines of your code?
if you check the document before this section of code is some part of the incorrect text already there?
Re: Word formatting problems -TabStops & TypeText
What happens if you put this line just before this block:
Code:
wdApp.ActiveDocument.Activate
Re: Word formatting problems -TabStops & TypeText
Pradeep, the code does use .Activate its just not shown in the snippet.
westconn, I cannot recreate the problem and was hoping I wouldn't have to create a special "trouble shooting" version of the app to solve this problem. The user is at a remote site and well, not very cooperative (and a little cranky).
The rest of the code is basically the same. It goes on to write the contents of a recordset to the document using the TypeText method, setting and clearing TabStops etc.
Re: Word formatting problems -TabStops & TypeText
what i was trying to determine was at what point the additional text was being inserted
is he using any different language packs etc, as the characters look chinese
what else he may be doing while the code is running
if the code is writing to a new document, what template is it based on
Re: Word formatting problems -TabStops & TypeText
There is no "additional text". The top of the sample graphic I posted is the normal output. The bottom is the corrupted output. I created the graphic by copying 3 lines of text from two different documents.
What is happening here is that this line of code
.Selection.TypeText Text:="B.C. CORONERS SERVICE" & vbTab & "TOXICOLOGY REPORT"
is printing each character at the exact same location/position.
Re: Word formatting problems -TabStops & TypeText
Quote:
Originally Posted by
brucevde
There is no "additional text". The top of the sample graphic I posted is the normal output. The bottom is the corrupted output. I created the graphic by copying 3 lines of text from two different documents.
What is happening here is that this line of code
.Selection.TypeText Text:="B.C. CORONERS SERVICE" & vbTab & "TOXICOLOGY REPORT"
is printing each character at the exact same location/position.
What code lines print those "2008-1865" text? I think problem might be near that.
Re: Word formatting problems -TabStops & TypeText
Hi Bruce
Nothing wrong with the code mentioned in post 1
I am curious (Same as Pete) as to how are you generating the rest of the document...
Can I see the rest of the code which deals with the last 3 lines?
Re: Word formatting problems -TabStops & TypeText
Quote:
There is no "additional text".
sorry, i thought it was all in the same document, rather than image of 2 docs
looks like it is just some corruption of the strings passed to the document, although the formatted numbers still print correctly
maybe comes back to what language packs
actually it almost looks like all the characters are printed one on top of the other
can you get /post a sample document, with the anomaly?
Re: Word formatting problems -TabStops & TypeText
This is just a guess:
As the problem happened on only 1 user's PC and not all the times, I think that PC has some problem with Ms-Word when it try to render that font (is that Arial?) at some particular sizes or Zoom.
Request a reinstall of Ms-Word to see what happens.
Sometimes I saw a similar sympton on webbrowser on my PC when I changed text size.
I don't think the problem is in your code although it is not "professional" as it uses Selection to move the pointer (as pete mentioned).
Re: Word formatting problems -TabStops & TypeText
Hello Bruce and all,
I realize this is an old thread, but I have encountered a nearly identical problem and I’m wondering how it was solved. We also have some printouts with several paragraphs, but all the characters in each paragraph are scruched to the same spot to look like blobs of characters in the line 1 column 1 of the immedate text.
We’re using Win2k3 and Office 2003. We use automation to generate the final documents in a medical transcription reporting application. Most of the document printouts are perfect, but in some installations (not all systems) we getting ~2/1000 printouts like this.
Did you determine the cause? And, how did you solve it?
Many thanks!