Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-22-2023, 03:05 AM
azurtem azurtem is offline Sorting a table full of images Windows 7 64bit Sorting a table full of images Office 2013
Novice
Sorting a table full of images
 
Join Date: Apr 2016
Location: nice, france
Posts: 7
azurtem is on a distinguished road
Question 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
The problem I have is that each cell in my table contains an image (barcode), not a string

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.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Sorting a Table lkirit Excel 3 10-30-2019 11:52 PM
Sorting a table full of images 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
Sorting a table full of images table spanning full page datto210 Word Tables 1 10-25-2010 12:39 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:25 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft