VISUAL BASIC.NET COM OPEN OFFICE

SOCRAM130684 15/08/2017 11:50:45
#475796
Bom dia galera, estou tentando inserir alguns dados do form1 em uma planilha já existente que esta em open office, porém preciso inserir em celulas e colunas especificas, encontrei o codigo abaixo e estou tentando adaptar a meu caso. Até agora não obtive sucesso, da o erro:

Error 5 Number of indices is less than the number of dimensions of the indexed array.


  Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

Dim oSM [ô]Root object for accessing OpenOffice from VB
Dim oDesk, oDoc As Object [ô]First objects from the API
Dim arg() [ô]Ignore it for the moment !

[ô]Instanciate OOo : this line is mandatory with VB for OOo API
oSM = CreateObject([Ô]com.sun.star.ServiceManager[Ô])

[ô]Create the first and most important service
oDesk = oSM.createInstance([Ô]com.sun.star.frame.Desktop[Ô])

[ô]Open an existing doc (pay attention to the syntax for first argument)
oDoc = oDesk.loadComponentFromURL([Ô]file:///C:/as.ods[Ô], [Ô]_blank[Ô], 0, arg())

osheet = oDoc.getSheets().getByIndex(0) [ô]seleciona primeira planilha

Call osheet.getCellByPosition(3, 1).SetValue(111) [ô]seta valor col,linha
Call osheet.getCellByPosition(3, 2).SetValue(222) [ô]seta valor col,linha
Call osheet.getCellByPosition(3, 3).SetString([Ô]Nilson[Ô]) [ô]seta valor da celular do tipo string
Call osheet.getCellByPosition(3, 5).SetFormula([Ô]=SUM(D2:D4)[Ô]) [ô]seta celula do tipo formula
[ô]Save the doc
Call oDoc.storeToURL([Ô]file:///C:/as.ods[Ô], arg())
oDoc.Close(True)
oDoc = Nothing
End Sub
SOCRAM130684 15/08/2017 13:10:24
#475798
Obs: Quando eu coloco arg(0) e mando executar o programa na linha abaixo apresenta o erro que segue:

Dim arg(0)
Linha:
[ô]Open an existing doc (pay attention to the syntax for first argument)
oDoc = oDesk.loadComponentFromURL([Ô]file:///C:/as.ods[Ô], [Ô]_blank[Ô], 0, arg(0))

Erro:
Tipo não correspondente. (Exceção de HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))
Tópico encerrado , respostas não são mais permitidas