Path to the current user profile, Info about the used template

Shared Libraries
Forum rules
For sharing working examples of macros / scripts. These can be in any script language supported by OpenOffice.org [Basic, Python, Netbean] or as source code files in Java or C# even - but requires the actual source code listing. This section is not for asking questions about writing your own macros.
Post Reply
User avatar
Lupp
Volunteer
Posts: 3693
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Path to the current user profile, Info about the used template

Post by Lupp »

Code: Select all

Sub showTemplateInfo(Optional pDoc As Object)
If IsMissing(pDoc) Then pDoc = ThisComponent
On Local Error Goto fail
MsgBox(templateInfo(pDoc))
Exit Sub
fail:
MsgBox("?No document!" )
End Sub

Sub showProfilePath()
MsgBox(userProfilePath())
End Sub

Function templateInfo(Optional pDoc As Object) REM Mainly for use in Calc formulas.
Dim tname As String, turl As String, out As String
If IsMissing(pDoc) Then pDoc = ThisComponent
turl  = pDoc.DocumentProperties.TemplateURL
If turl="" Then turl = "<url missing>"
tname = pDoc.DocumentProperties.TemplateName
REM This is the name of the link shown by the template manager.
If tname="" Then tname = "<missing>"
out   = turl & "?" & "name=" & tname
templateInfo _
      = out
End Function

Function userProfilePath() REM For use in Calc e.g.
Dim substService As Object, out As String
substService = CreateUNOService("com.sun.star.util.PathSubstitution")
out          = substService.getSubstituteVariableValue("$(user)")
userProfilePath _
             = out
End Function
On Windows 10: LibreOffice 25.2.4 and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
Post Reply