I can do most things now but I'm stuck on setting the number of decimal places in a cell.
Looking around I've found odd bits of code and I've played around with it, end up with the code below.
I read somewhere that if oLoc isn't given then it uses default settings?
I get a '440 Automation error' on Set oLoc = oSM.Bridge_GetStruct, and if I rem it out I get the '438' error on the last line.
Code: Select all
'initial set up OK to here
Dim oCell As Object
Set oCell = oSheet.getCellByPosition(1, 1)
Call oCell.setValue(1000)
'OK to here, sheet opens and the cell is set to 1000
Dim oNumberFormats As Object
Dim NumberFormatString As String
Dim NumberFormatId As Long
Dim oLoc As Object
'API says it's a 'struct' but I'm not sure if this line is correct
'Set oLoc = oSM.Bridge_GetStruct("com.sun.star.lang.locale") '440 Automation error
'Set oLoc.language = "en"
'Set oLoc.Country = "gb"
Set oNumberFormats = oDoc.NumberFormats
NumberFormatString = "#,##0.00"
NumberFormatId = oNumberFormats.queryKey(NumberFormatString, oLoc, True)
If NumberFormatId = -1 Then
NumberFormatId = oNumberFormats.AddNew(NumberFormatString, oLoc)
End If
MsgBox NumberFormatId '=106
Call oCell.NumberFormats(NumberFormatId) 'error 438 Object doesn't support this property or method
Regards
Peter