Obtaining user details

6 posts / 0 new
Last post
JohnGoodchild
Offline
Joined: 11/09/2015 - 12:46
Obtaining user details

Hi,
I have been trying to find a way to get the user details to pre-load a dialogbox with a possible path - eg C:\Users\jdgoodchild\Documents\IDEA9\Exports.ILB
Using set userprofile at a DOS prompt, I get USERPROFILE=C:\Users\jdgoodchild - just what I want. So I tried
Sub Main
Dim wshShell
Dim wshSystemEnv
Dim WScript
 
Set wshShell = CreateObject( "WScript.Shell" )
Set wshSystemEnv = wshShell.Environment( "PROCESS" )
''WScript.Echo "SYSTEM:  USERPROFILE=" & wshSystemEnv( "USERPROFILE" )
MsgBox wshSystemEnv("USERPROFILE") 
End Sub
 
Running gives - Error on line 9 - Application defined or object defined error
(Line 9 is MsgBox wshSystemEnv("USERPROFILE") )
Any thoughts please. Thanks, John.

Brian Element's picture
Brian Element
Offline
Joined: 07/11/2012 - 19:57

Hi John,

This seems to work for me:

Sub Main
 Dim objShell As Object
 Set objShell = CreateObject("WScript.Shell")
  userProfilePath = objShell.ExpandEnvironmentStrings("%UserProfile%")
  MsgBox userProfilePath
 Set objShell = Nothing
End Sub

Let me know if it is what you are looking for.

Thanks

Brian

JohnGoodchild
Offline
Joined: 11/09/2015 - 12:46

Thanks Brian, that was exactly what I was looking for!
Also thank you for the time you put in to making this site such a valuable resource.
John

Brian Element's picture
Brian Element
Offline
Joined: 07/11/2012 - 19:57

Hi John, glad I was able to help and also I am glad you enjoy the site.

Brian

gabriel
Offline
Joined: 03/10/2020 - 17:09

Hi i am trying to make this may you guide what is the correct way:
 
 
Sub Main
 
Call des_saldo
End Sub
 
 
 
Function des_saldo
 
Dim usuario As String
usuario ="gchandler"
 
Set db = Client.OpenDatabase("SEMIF_9.IMD")
Set task = db.ExportDatabase
task.IncludeAllFields
eqn = "VALIDACION_DIAS_MORA_AUDIT <> ""OK"""
task.PerformTask "C:\Users\"   "&usuario&"    "\Banco Internacional de Costa Rica, S.A\Gestión de Auditoría Interna - Auditoria Interna-Seguimiento\Auditoria_Continua\REPORTES\01-PRESTAMOS ESPECIFICOS Y LINEAS\Desviaciones Días Mora.XLS", "Database", "XLS8", 1, db.Count, eqn
Set db = Nothing
Set task = Nothing
End Function

Brian Element's picture
Brian Element
Offline
Joined: 07/11/2012 - 19:57

I think you have too many quotes around the variable, this might work:

task.PerformTask "C:\Users\" & usuario & "\Banco Internacional de Costa Rica, S.A\Gestión de Auditoría Interna - Auditoria Interna-Seguimiento\Auditoria_Continua\REPORTES\01-PRESTAMOS ESPECIFICOS Y LINEAS\Desviaciones Días Mora.XLS", "Database", "XLS8", 1, db.Count, eqn

Also make sure you have spaces around the & and the variable.

Also you have XLS8 where I think it should be XLSX.

Try this out and see if it works.

You can also try it manually and then go to the history to look for the proper syntax if you haven't already.

Good luck.