Results 1 to 7 of 7

Thread: Delete a line in all cells in table simultaniously

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2005
    Posts
    91

    Delete a line in all cells in table simultaniously

    I use Word automation in my VB6 application.
    I have a table in my Word doc, has 12 cells.
    I have in all cells 2 lines. First line has text second line just the enter (PI sign).
    Now i want the second empty line deleted in all cells and in one go, looping through cells is no option.
    I believe the lines are available as paragraphs
    So something like
    Code:
    ATable.range.paragraphs(1).delete
    So i can't use ATable.range.cells i think because then i have to mention a certain cell.
    Any suggestions?

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Delete a line in all cells in table simultaniously

    If I understand your situation correctly, you will have to go cell by cell. It may be better to parse out the carriage return during the population instead.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Oct 2005
    Posts
    91

    Re: Delete a line in all cells in table simultaniously

    I want to avoid going cell by cell, for timeconsuming reasons, beceause in some situations there can be lots of tables in one document.
    Now i have found a simular way of approuching a paragraph (line) of all cells for entire table at once only this is for alignment.
    It vertically aligns all first paragraphs of all table cells, i use a spacebefore.
    aTable.range.paragraphs(1).Spacebefore = 12
    Now this can be just good luck but this alignment works, but i can allso use
    aTable.range.paragraphs.Last.Spacebefore = 12
    But using this method for editing er deleting a paragraph/line doesn't seem to work

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

    Re: Delete a line in all cells in table simultaniously

    i tried your example above but it only worked in 1 cell and paragraphs.last seems to be after the table

    VB Code:
    1. For Each atable In ActiveDocument.Tables
    2.     For Each acell In atable.Range.Cells
    3.         acell.Range.Paragraphs(2).Range.Delete
    4.     Next
    5.  
    6. Next

    this code does what you want, but as you said it is a bit slow, took 126 seconds to do 620 tables of 20 cells on my laptop

    pete

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Oct 2005
    Posts
    91

    Re: Delete a line in all cells in table simultaniously

    The example with spacebefore does work for me for alignment tried on two pc's , i can mention it is done directly after a Mailmerge.execute. But doesn't matter maybe some sideeffect.
    Now i tryed deleting a certain paragraph and this only is done in one cell like you said.


    VB Code:
    1. 'This does only delete paragraph in one cell
    2. aTable.range.paragraphs(1).range.delete
    3. 'or
    4. aTable.range.paragraphs(2).range.delete

    Now preventing the extra enter during populating maybe difficult. Because it comes from selected fields for a Mailmerge and complicated to explain all the steps.
    The result is i have really two lines visible
    Example:
    FirstLine¶
    O
    The tablecellseparator sign O allso shows as a line. So i realy have to remove the ¶ from the first line. I will look ferther for a fast way to remove it for all cells, if not found i will have to leave the extra enter.
    Added info:
    Allso the FirstLine mentioned is a field not plain text so {MyFieled}¶
    This maybe will make it more difficult to remove the ¶
    Last edited by lvermeersch; Jun 25th, 2006 at 01:49 AM.

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Oct 2005
    Posts
    91

    Re: Delete a line in all cells in table simultaniously

    Okey. I found an easy and fast solution.
    Because all the enter ¶ signs in my document or unwanted (each enter at the first and only line)
    i can easally find and replace them with a Find.Execute Replace:=wdReplaceAll
    I allready tried it and works great :-)

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

    Re: Delete a line in all cells in table simultaniously

    too easy..... lol

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