Results 1 to 11 of 11

Thread: Word formatting problems -TabStops & TypeText

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    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
    Attached Images Attached Images  

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    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?
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Word formatting problems -TabStops & TypeText

    What happens if you put this line just before this block:

    Code:
    wdApp.ActiveDocument.Activate
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    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.

  5. #5
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    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
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    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.

  7. #7
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Word formatting problems -TabStops & TypeText

    Quote Originally Posted by brucevde View Post
    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.
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  8. #8
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    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?
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  9. #9
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Word formatting problems -TabStops & TypeText

    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?
    Last edited by westconn1; May 4th, 2009 at 06:42 AM.
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  10. #10
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    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).
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

  11. #11
    New Member
    Join Date
    Jul 2011
    Posts
    1

    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!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width