Olá, não sei exatamente o resultado que quer chegar, esta macro serve de ideia: Arquivo do teste
Sub Comecar
Call IrPara "ITENS"
Call TESTANDO
end Sub
'============
Sub TESTANDO
Dim Plan As Object
Dim Var1 As String
Dim oSel As Object
dim document as object
dim dispatcher as object
Call IrPara "ÍNDICE"
Call DeslocarAbaixo 1
' ===== Pegar a variavel Var1, a Pesquisar
oSel = ThisComponent.getCurrentSelection()
Var1 = oSel.getString()
' While Var1 <>""
'TESTE
if Var1 = "" then
MsgBox "Nº ITEM em branco", 0, "A t e n ç ã o"
else
' ===== Ir para o Banco de Dados
Call IrPara "ITENS2"
Call SelecionarColuna
' ===== Fazer a busca, achar a célula com a informação
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dim args3(20) as new com.sun.star.beans.PropertyValue
args3(0).Name = "SearchItem.StyleFamily"
args3(0).Value = 2
args3(1).Name = "SearchItem.CellType"
args3(1).Value = 0
args3(2).Name = "SearchItem.RowDirection"
args3(2).Value = true
args3(3).Name = "SearchItem.AllTables"
args3(3).Value = false
args3(4).Name = "SearchItem.SearchFiltered"
args3(4).Value = false
args3(5).Name = "SearchItem.Backward"
args3(5).Value = false
args3(6).Name = "SearchItem.Pattern"
args3(6).Value = false
args3(7).Name = "SearchItem.Content"
args3(7).Value = false
args3(8).Name = "SearchItem.AsianOptions"
args3(8).Value = false
args3(9).Name = "SearchItem.AlgorithmType"
args3(9).Value = 0
args3(10).Name = "SearchItem.SearchFlags"
args3(10).Value = 0
args3(11).Name = "SearchItem.SearchString"
args3(11).Value = Var1 '<=====VARIAVEL
args3(12).Name = "SearchItem.ReplaceString"
args3(12).Value = ""
args3(13).Name = "SearchItem.Locale"
args3(13).Value = 255
args3(14).Name = "SearchItem.ChangedChars"
args3(14).Value = 2
args3(15).Name = "SearchItem.DeletedChars"
args3(15).Value = 2
args3(16).Name = "SearchItem.InsertedChars"
args3(16).Value = 2
args3(17).Name = "SearchItem.TransliterateFlags"
args3(17).Value = 256
args3(18).Name = "SearchItem.Command"
args3(18).Value = 0
args3(19).Name = "SearchItem.SearchFormatted"
args3(19).Value = false
args3(20).Name = "SearchItem.AlgorithmType2"
args3(20).Value = 1
dispatcher.executeDispatch(document, ".uno:ExecuteSearch", "", 0, args3())
dim args4(1) as new com.sun.star.beans.PropertyValue
args4(0).Name = "By"
args4(0).Value = 1
args4(1).Name = "Sel"
args4(1).Value = false
dispatcher.executeDispatch(document, ".uno:GoLeftToStartOfData", "", 0, args4())
'===== Abaixo vai a Chamada da Macro a executar.
' Call MacroExecutar
Call TESTANDO
end If
end Sub
' ============== SUBMACROS ========================================================
Sub MacroExecutar
'montar rotina da macro
end Sub
'================================================|
sub IrPara (xlocal as string)
'exemplo uso: IrPara "Planilha.A1" ou "Planila1.A1:B3" ou "NomeArea"
'================================================|
Dim document As Object
Dim dispatcher As Object
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "ToPoint"
args1(0).Value = xlocal
dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args1())
end sub
'================================================|
sub DeslocarAbaixo (xqt As Integer)
' xqt = quantidade de linhas
' uso: DeslocarAbaixo 3 '3 linhas
'================================================|
Dim document As Object
Dim dispatcher As Object
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dim args1(1) as new com.sun.star.beans.PropertyValue
args1(0).Name = "By"
args1(0).Value = xqt '<==== quantidade linhas.
args1(1).Name = "Sel"
args1(1).Value = false
dispatcher.executeDispatch(document, ".uno:GoDown", "", 0, args1())
end sub
'=====================================================================
sub SelecionarColuna
'=====================================================================
dim document as object
dim dispatcher as object
rem get access to the document
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dim args2(0) as new com.sun.star.beans.PropertyValue
args2(0).Name = "By"
args2(0).Value = 1
dispatcher.executeDispatch(document, ".uno:GoDownToEndOfDataSel", "", 0, args2())
end sub
Caso a resposta atendeu sua necessidade, por gentileza, click na bolinha a esquerda da resposta, para finalizar a pergunta.