View Single Post
 
Old 07-19-2024, 02:04 AM
arabgogs arabgogs is offline Windows 11 Office 2021
Novice
 
Join Date: Jul 2024
Posts: 1
arabgogs is on a distinguished road
Default Converting tables to images - landscape issue.

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.

please note, when I comment out "tbl.PreferredWidth = 0" all rows display, however only half of the columns then display. This was an issue i had found previously. Pulling hair out!!

Code:
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.
Regards

Gordon
Reply With Quote