Hello...Does anybody know how to get the default folder "Documents" on Windows 10 by using macro codes?

I´m working on Calc and I need convert ranges in PDF files (I´ve ever figured out this) and then I need create a folder and saving converted ranges on that folder on the “MyDocument” on Windows 10. The problem is…How does it get the USER for each user that will use my macro code?

1 Like

Try

Function GetSubstVar(ByVal var As String) As String
  Dim oPathSubstitution
  oPathSubstitution=CreateUnoService("com.sun.star.util.PathSubstitution")
  GetSubstVar=oPathSubstitution.getSubstituteVariableValue(var)
End Function

Sub TestGetWorkPath
  Msgbox GetSubstVar("$(work)")
End Sub
2 Likes

… or have a go with (re-)modifying this which i got elsewhere on here:

Sub Open_MainProjectFolder
Dim stDir as String, Folder as String,partpath As String
Dim oDoc as Object

partpath = “ARCHBASE” REM 'alter as needed …
oDoc = ThisComponent.Parent
stDir = Left(oDoc.Location,Len(oDoc.Location)-Len(oDoc.Title)-Len(partpath))
Folder = stDir
'Url = oDoc.URL
'Path = ConvertFromUrl(Url)
'Folder = DirectoryNameoutofPath(Url(),"/")
'Folder = ConvertFromUrl(Folder)
Shell(“C:\Windows\explorer.exe”, 1, Folder)
End Sub

I´ve learned more one…really interesting…the code opens the folder window. I didn´t know that it´s possible.Thanks.

Thanks, thanks, thanks a million…The code is beautiful.

1 Like