1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| Option Explicit
Sub bouton_cliquer
Dim dlg As Object
Dim cel As Object
Dim url as String
' url dossier notice
url = urlDossierParent(ThisComponent.getURL()) & "/Notice_facture"
' boite de dialogue "Ouvrir"
dlg = CreateUnoService("com.sun.star.ui.dialogs.OfficeFilePicker")
' filtres
dlg.AppendFilter("Fichier pdf (*.pdf)", "*.pdf")
dlg.setCurrentFilter("Fichier pdf (*.pdf)","*.pdf")
' chemin par défaut pour la boîte de dialogue
dlg.SetDisplayDirectory(url)
' affiche la boîte de dialogue "Ouvrir"
If dlg.Execute() = 1 Then
url = ConvertToURL(dlg.Files(0))
cel = thisComponent.Sheets.getbyName("Feuille1").getCellRangebyName("C3")
call lien(cel,"Notice.pdf",url)
End If
End sub
Sub ActualiseLien
Dim url as String
Dim nom as String
Dim cel As Object
Dim fds as object
Dim fld as object
url = ThisComponent.getURL()
cel = thisComponent.Sheets.getbyName("Feuille1").getCellRangebyName("C3")
fds = cel.TextFields
If fds.Count > 0 then
fld = fds.getByIndex(0)
url = urlDossierParent(url) & Mid(fld.url, InStr(1, fld.url, "/Notice_facture/"))
fld.url = url
End If
End sub
Sub lien(cel as Object,txt as String, url as String)
Dim fld As Object
Dim ctx As Object
fld = ThisComponent.createInstance("com.sun.star.text.TextField.URL")
fld.Representation = IIF(txt = "", url, txt)
fld.URL = url
cel.String = ""
ctx = Cel.getText("")
ctx.insertTextContent(ctx.createTextCursor(), fld, False)
End Sub
Function urlDossierParent(url as String) As String
Dim str As String
Dim n As Long
str = url
For n = Len(str) To 1 Step -1
If Mid(str, n, 1) = "/" Then Exit For
Next n
urlDossierParent = Left(str, n - 1)
End Function |
Partager