Merci Nicolas et Jean-Luc pour vos pistes,
Voilà le résultat ci-dessous un bout de code pas entièrement nettoyé faute de temps
qui utilise
getCellRangesByName avec le s cela change tout
Cordialement
Jean-Luc
Sub CopierUnTableauDansUnTableauDUnePage(oMonDocumentCUTDUP,NomFeuilleTableauCUTDUP,PlageCellulesAcopierCUTDUP,oMonDocumentTexteCUTDUP,NomDuTableauCUTDUP,PositionDeLaCopieDansLeTableauCUTDUP,LieuDAppelCUTDUP)
Dim oMonTableauCUTDUP, oLeTableauCUTDUP, oMaFeuilleCUTDUP, oMaCelluleCUTDUP, oCurseurTexteCUTDUP, oCurseurVisibleCUTDUP, fenetreAfficherCUTDUP As Object
Dim NomDuFichierCalcCUTDUP, PlageAbsolueCellulesAcopierCUTDUP, LesPlagesDeCellulesCUTDUP (0 to 10) As String
Dim LeDiagrammeExisteCUTDUP As Boolean
Dim oDispatchHelperCUTDUP As Object
' dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
Dim ArgsCUTDUP(0) as new com.sun.star.beans.PropertyValue
dim PysDoc,PysCopie as object, PysDestination, oDocCtrl, oDocFrame, oDrawDoc, oDrawPage , oDrawDocCtrl, oDrawDocFrame as object
Dim NiveauDebugCUTDUP, NbrDeTableauCUTDUP,DeplacementHorizontalCUTDUP, DeplacementVerticalCUTDUP, iCUTDUP As Integer
NiveauDebugCUTDUP=1
MessageDebug(NiveauDebugCUTDUP,3,582,"CopierUnTableauDansUnePage")
NomDuFichierCalcCUTDUP = oMonDocumentCUTDUP.Location 'l'argument n'est pas facultatif
' On Error Goto errmodifCUTDUP
fenetreAfficherCUTDUP= oMonDocumentCUTDUP.CurrentController.Frame.ContainerWindow
fenetreAfficherCUtDUP.toFront
oMaFeuilleCUTDUP = oMonDocumentCUTDUP.sheets.getByName(NomFeuilleTableauCUTDUP)
If oMaFeuilleCUTDUP.Name =NomFeuilleTableauCUTDUP and Not(LaChaineContientLesCaracteres(PlageCellulesAcopierCUTDUP,";")) and PlageCellulesAcopierCUTDUP<>"" Then
oMonTableauCUTDUP = oMaFeuilleCUTDUP.getCellRangeByName(PlageCellulesAcopierCUTDUP)
Else
LesPlagesDeCellulesCUTDUP=decoupage_d_une_chaine_avec_separateur(PlageCellulesAcopierCUTDUP,";")
' Xray LesPlagesDeCellulesCUTDUP
PlageAbsolueCellulesAcopierCUTDUP=NomFeuilleTableauCUTDUP & "." & LesPlagesDeCellulesCUTDUP(0)
For iCUTDUP=1 to UBound(LesPlagesDeCellulesCUTDUP)
PlageAbsolueCellulesAcopierCUTDUP=PlageAbsolueCellulesAcopierCUTDUP & ";" & NomFeuilleTableauCUTDUP & "." & LesPlagesDeCellulesCUTDUP(1)
Next iCUTDUP
Print(NomFeuilleTableauCUTDUP & " " & PlageCellulesAcopierCUTDUP & " " & NomDuTableauCUTDUP & " " & PositionDeLaCopieDansLeTableauCUTDUP & " " &NomFeuilleTableauCUTDUP & " : " & PlageAbsolueCellulesAcopierCUTDUP)
' Xray oMaFeuilleCUTDUP
oMonTableauCUTDUP = oMonDocumentCUTDUP.sheets.getCellRangesByName(PlageAbsolueCellulesAcopierCUTDUP)
' oMonTableauCUTDUP = oMonDocumentCUTDUP.sheets.getCellRangesByName(NomFeuilleTableauCUTDUP &"." & PlageCellulesAcopierCUTDUP &";" & NomFeuilleTableauCUTDUP & ".P41:Y50")
' ;P41:Y50
Xray oMonTableauCUTDUP
Dim oRanges, oCtrl, plage As object
oCtrl = oMonDocumentCUTDUP.CurrentController
oRanges = oMonDocumentCUTDUP.createInstance("com.sun.star.sheet.SheetCellRanges")
' plages = oDoc.Sheets.getCellRangesByName(refs)
for each plage in oMonTableauCUTDUP
oRanges.addRangeAddress(plage.RangeAddress, False)
next plage
oCtrl.select(oRanges)
print("Stop")
End If
thiscomponent.currentcontroller.select(oMonTableauCUTDUP)
oLeTableauCUTDUP = ThisComponent.CurrentController.Frame
' Xray oLeTableauCUTDUP
oDispatchHelperCUTDUP = createUnoService("com.sun.star.frame.DispatchHelper")
print ("le tableau est sélectionné ?")
oDispatchHelperCUTDUP.executeDispatch(oLeTableauCUTDUP , ".uno:Copy", "", 0, Array())
fenetreAfficherCUTDUP= oMonDocumentTexteCUTDUP.CurrentController.Frame.ContainerWindow
fenetreAfficherCUtDUP.toFront
If ThisComponent.Title<>oMonDocumentTexteCUTDUP.Title Then
acDocActiver(oMonDocumentTexteCUTDUP.Title)
If ThisComponent.Title<>oMonDocumentTexteCUTDUP.Title Then
print("le document n'est pas activé ThisComponent.CurrentController.Select(oMonTableauCUDDUP)")
Xray ThisComponent
EnregistrerEtFermer(oMonDocumentCUTDUP)
EnregistrerE(oMonDocumentTexteCUTDUP)
End If
End If
oMonTableauCUTDUP = oMonDocumentTexteCUTDUP.createInstance("com.sun.star.text.TextTable")
oMonTableauCUTDUP = FindObjectByName(oMonDocumentTexteCUTDUP.TextTables,NomDuTableauCUTDUP, "com.sun.star.text.TextTable")
oMaCelluleCUTDUP=oMonTableauCUTDUP.getCellByName(PositionDeLaCopieDansLeTableauCUTDUP)
If IsEmpty(oMaCelluleCUTDUP)or IsNull(oMaCelluleCUTDUP) Then
Print("La cellule n'est pas trouvé " & PositionDeLaCopieDansLeTableauCUTDUP)
Xray oMonTableauCUTDUP
Xray oMaCelluleCUTDUP
oMaCelluleCUTDUP=oMonTableauCUTDUP.getCellByName("A1")
Else
' Xray oMaCelluleCUTDUP
End If
oCurseurTexteCUTDUP= oMaCelluleCUTDUP.createTextCursor
oCurseurVisibleCUTDUP=oMonDocumentTexteCUTDUP.currentcontroller.ViewCursor
If IsEmpty(oCurseurVisibleCUTDUP.Cell) then
oCurseurVisibleCUTDUP.jumpToPage(1)
oCurseurVisibleCUTDUP.gotoRange(oCurseurTexteCUTDUP,False)
Else
oCurseurVisibleCUTDUP.gotoRange(oCurseurTexteCUTDUP,False)
End If
If oCurseurVisibleCUTDUP.Cell.CellName = PositionDeLaCopieDansLeTableauCUTDUP Then
Else
Print(" CurseurVisibleCUTDUP 2")
Xray oCurseurVisibleCUTDUP
End If
dim document as object
document = ThisComponent.CurrentController.Frame 'com.sun.star.comp.framework.Frame
' Xray document
' Xray oMonDocumentTexteCUTDUP.CurrentController.Frame
dim args6(0) as new com.sun.star.beans.PropertyValue
args6(0).Name = "SelectedFormat"
args6(0).Value = 3 '3 Copie au paragraphe 1 2 et 4 pas de copie
oDispatchHelperCUTDUP.executeDispatch( document, ".uno:ClipboardFormatItems", "", 0, args6()) 'copie dans le tableau
oDispatchHelperCUTDUP.executeDispatch(document, ".uno:SetAnchorToChar", "", 0, Array())
Exit Sub
errmodifCUTDUP:
print ("Dans le Programme ModifierUnDiagramme L'instruction n'existe pas erreur non Bloquante N°:" & Err & " " & Error & "à la ligne " & Erl)
' Resume Next
End Sub ' CopierUnTableauDansUnTableauDUnePage 8