#1
|
|||
|
|||
Sorting a table full of images
Hi
I'm trying to modify a table so as to have it's cells sorted from top to bottom and then from left to right I came across this VBA script, generously shared by Greg Maxey : Table Re-sorter Code:
Option Explicit Dim m_oTbl As Word.Table Sub SortTable() 'Set the table object = the table with the selection On Error GoTo Err_Handler: Set m_oTbl = Selection.Tables(1) 'Table must be uniform (not split or merged cells) If Not m_oTbl.Uniform Then MsgBox "The selected table has split or merge cells and cannot be sorted with this procedure", vbInformation + vbOKOnly, "Non-Uniform Table" Exit Sub End If TableSort_Re_Sort Exit Sub Err_Handler: MsgBox "Select a table an try again.", vbInformation + vbOKCancel, "Table Not Selected" End Sub Sub TableSort_Re_Sort(Optional bTopToBottom As Boolean = True) Dim oCell As Cell Dim arrData() As String Dim i As Long, j As Long, k As Long 'Initialize the array with no elements ReDim arrData(i) 'Load the array with data in table. Skip loading empty cells For Each oCell In m_oTbl.Range.Cells If Left(oCell.Range, Len(oCell.Range) - 2) <> "" Then ReDim Preserve arrData(i) arrData(i) = Left(oCell.Range, Len(oCell.Range) - 2) i = i + 1 End If Next 'Sort the array WordBasic.SortArray arrData 'Delete content of table m_oTbl.Range.Delete 'Reset counter i = 0 'Fill table with sorted results If bTopToBottom Then For k = 1 To m_oTbl.Columns.Count For j = 1 To m_oTbl.Rows.Count m_oTbl.Cell(j, k).Range.Text = arrData(i) 'Get out when lasted array element has been inserted in table If i < UBound(arrData) Then i = i + 1 Else GoTo lbl_Exit End If Next Next Else For Each oCell In m_oTbl.Range.Cells oCell.Range = arrData(i) 'Get out when lasted array element has been inserted in table If i < UBound(arrData) Then i = i + 1 Else GoTo lbl_Exit End If Next End If lbl_Exit: Exit Sub End Sub Is it possible to adapt Greg's code to handle images ? Using a different data type e.g. InlineShapes ? Regards yann Last edited by azurtem; 07-23-2023 at 02:03 AM. |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Sorting a Table | lkirit | Excel | 3 | 10-30-2019 11:52 PM |
Opening all selected images, resizing images and placing them into a table. | John Livewire | Word VBA | 1 | 09-15-2017 11:24 PM |
How to auto-split a table at FULL rows? | pstein | Word | 5 | 03-27-2012 02:48 PM |
Sorting records with embeded images | Karen222 | Excel | 0 | 01-09-2012 07:05 PM |
table spanning full page | datto210 | Word Tables | 1 | 10-25-2010 12:39 PM |