Boa tarde!
Fiz uma macro para ser usada na Planilha1, essa macro vai ser repetida diversas vezes, porém quando eu chamo a macro através de um botão, geralmente ela não funciona até eu clicar em alguma célula da planilha onde ela deve ser executada.
Macro:
Sub GerarPDF
For i = 1 to 105 Step 1
Call Module1.Copiaecola
Wait 350
Call Module2.MacroPDF
Next
Wait 200
Call Module3.Finalizar
End Sub
A Sub Copiaecola:
Sub Copiaecola
rem ----------------------------------------------------------------------
rem define variables
dim document as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
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 = "$B$10"
dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args1())
rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:Copy", "", 0, Array())
rem ----------------------------------------------------------------------
dim args3(0) as new com.sun.star.beans.PropertyValue
args3(0).Name = "ToPoint"
args3(0).Value = "$B$9"
dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args3())
rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:PasteOnlyValue", "", 0, Array())
end sub
Por fim a Sub MacroPDF
Sub MacroPDF
rem ----------------------------------------------------------------------
rem define variables
dim document as object
dim dispatcher as object
Dim oPlan as Object, oCel as Object
Dim sNomeArquivo as String
rem ----------------------------------------------------------------------
rem get access to the document
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
oPlan = ThisComponent.Sheets.getByName( "Reg de Publicador" )
oCel = oPlan.getCellRangeByName( "B3" )
rem ----------------------------------------------------------------------
dim args1(1) as new com.sun.star.beans.PropertyValue
args1(0).Name = "URL"
args1(0).Value = "file:///C:/Users/Lucas/Documents/RELAT C/" & oCel.String & "-" & Format(Date, "yyyymmdd") &".pdf"
args1(1).Name = "FilterName"
args1(1).Value = "calc_pdf_Export"
dispatcher.executeDispatch(document, ".uno:ExportDirectToPDF", "", 0, args1())
End Sub
Poderiam me ajudar?