sub Autofit_GS
rem ----------------------------------------------------------------------
dim document as object
dim dispatcher as object
rem ----------------------------------------------------------------------
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
rem ----------------------------------------------------------------------
dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "ToPoint" : args1(0).Value = "$A$1"
dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args1())
rem ----------------------------------------------------------------------
dim args2(0) as new com.sun.star.beans.PropertyValue
args2(0).Name = "Sel" : args2(0).Value = true
dispatcher.executeDispatch(document, ".uno:GoToEndOfData", "", 0, args2())
rem ----------------------------------------------------------------------
dim args3(0) as new com.sun.star.beans.PropertyValue
args3(0).Name = "WrapText" : args3(0).Value = false
dispatcher.executeDispatch(document, ".uno:WrapText", "", 0, args3())
rem ----------------------------------------------------------------------
dim args11(0) as new com.sun.star.beans.PropertyValue
args11(0).Name = "aExtraWidth" : args11(0).Value = 0
CreateUnoService("com.sun.star.frame.DispatchHelper") _
.executeDispatch(ThisComponent.CurrentController _
.Frame, ".uno:SetOptimalColumnWidth", "", 0, args11())
End Sub