Macro to set column width of table.

I can set the column width of first table in a document to optimum. How can I set it for all tables.

Sub SetTableOptimumWidth

Dim oDispHelper 'Dispatch helper
Dim oFrame 'Current window frame.
Dim oTable 'First table in the document.
Dim oVCursor 'The view cursor
Dim s$

oTable = ThisComponent.getTextTables().getByIndex(0)
ThisComponent.getCurrentController().select(oTable)
oVCursor = ThisComponent.getCurrentController().getViewCursor()
oVCursor.gotoEnd(True)
oVCursor.gotoEnd(True)
oFrame = ThisComponent.CurrentController.Frame
oDispHelper = createUnoService(“com.sun.star.frame.DispatchHelper”)
s$ = “.uno:SetOptimalColumnWidth”
oDispHelper.executeDispatch(oFrame, s, “”, 0, Array())
End Sub