Consulting

Results 1 to 5 of 5

Thread: Convert tables to Images - bottom rows missing

  1. #1
    VBAX Regular arangogs's Avatar
    Joined
    Jun 2009
    Location
    Ayrshire, Scotland
    Posts
    21
    Location

    Convert tables to Images - bottom rows missing

    Hi All,

    I am attempting to convert all tables in a document to images, the code seems to work fine when the tables\pages are in portrait orientation. The issue of bottom rows being missing presents itself when landscape orientation has been applied.

    There is a prepping process that unmerges cells and splits tables per individual page, where appropriate.

    I have attempted many fix options, all to no avail. Code used below.

    Sub ConvertTablesToImages(ByVal currentDoc As Word.Document)
    
    
         Dim tbl As Table, rng As Range, i As Integer
         Dim tWidth As Long, tHeight As Long
        
        For i = currentDoc.Tables.Count To 1 Step -1
            Set tbl = currentDoc.Tables(i)
            tbl.Select
            Set rng = tbl.Range
            'Get table width prior to resetting
            'tWidth = ReturnTableWidth(tbl)
            'tHeight = ReturnTableHeight(tbl)
            tbl.PreferredWidth = 0
            tbl.Range.CopyAsPicture
            
            rng.Collapse Direction:=wdCollapseStart
            'rng.Collapse Direction:=wdCollapseEnd
            
            tbl.Delete
            rng.PasteSpecial DataType:=wdPasteEnhancedMetafile
         
            'rng.ShapeRange(1).LockAspectRatio = msoFalse
            rng.ShapeRange(1).ConvertToInlineShape
        
            
        Next
    End Sub
    any help appreciated, tearing my hair out with this one.

    Thanks

    Gordon

  2. #2
    VBAX Expert Dave's Avatar
    Joined
    Mar 2005
    Posts
    855
    Location
    Hi Gordon. Not sure if this will help, but here is some code that Macropod provided me to keep tables on the same page... it sounds like this may be an issue for you. HTH. Dave
    'prevent tables from splitting page
    For Each Otbl In ActiveDocument.Tables
    Otbl.Range.Paragraphs.keepwithnext = True
    For Each Ocel In Otbl.Rows.last.Range.Cells
    Ocel.Range.Paragraphs.last.keepwithnext = False
    Next Ocel
    Next Otbl

  3. #3
    VBAX Regular arangogs's Avatar
    Joined
    Jun 2009
    Location
    Ayrshire, Scotland
    Posts
    21
    Location
    Many thanks for the response Dave, much appreciated.

    Unfortunately, the tables sometimes span many pages, thus this would not work. As i said, it is a the orientation that appears to be the issue, further head scratching and testing yesterday. I had originally had an issue with the image only pasting half the columns, resolved by adding "tbl.PreferredWidth = 0"

    Removing this line yesterday, led to all rows being displayed, but back to only half of the columns again


    more trawling of internet today, i feel, for the nugget of info i require.

    Thanks or your help once again

  4. #4
    VBAX Expert Dave's Avatar
    Joined
    Mar 2005
    Posts
    855
    Location
    Hi again Gordon. You can set your table width with the following code. You can also trial removing the commented code to see what happens. HTH. Dave
    With CurrentDoc.PageSetup
    TblWdth = .PageWidth - .LeftMargin - .RightMargin - .Gutter
    End With
    'format table
    With CurrentDoc.Tables(1)
    '.AutoFormat Format:=16, applyborders:=True
    '.AutoFitBehavior (0)
    .Columns.Width = TblWdth / .Columns.Count
    End With
    edit: this will set all of your columns to the same width

  5. #5
    VBAX Regular arangogs's Avatar
    Joined
    Jun 2009
    Location
    Ayrshire, Scotland
    Posts
    21
    Location
    Hi Dave,

    Many thanks for the response once again. I have been toiling with many scenario's since my last post and finally managed to get the code working, bizarrely I have to perform effectively the same actions in varying ways dependant on the orientation of the page. resetting the width on landscape.

    I am trying to iron out a couple of niggly bits at the moment, but once i am done, I will post the code here.


    Thanks again for your help.

    Gordon

Tags for this Thread

Posting Permissions

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