Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Obtaining Desktop path from VBA code

Status
Not open for further replies.

trifest

Programmer
Sep 5, 2002
52
0
0
US
I was wondering if there was some environment variable i could call from the vba code to obtain the users desktop path since they'll be different because of the Windows version and user profile.

i'm trying to copy a file to their desktop automatically but need to dynamically pull the desktop path from the code. any help would be greatly appreciated.
 
If you have Scripting available:
Code:
Dim WshShell As Object
Dim strDesktop as String
set WshShell = WScript.CreateObject("WScript.Shell")
strDesktop = WshShell.SpecialFolders("Desktop")

hth

Ben

----------------------------------------------
Ben O'Hara "Where are all the stupid people from...
...And how'd they get so dumb?"
rockband.gif
NoFX-The Decline
----------------------------------------------
 
If you don't have WScript, there are some api codes at vbNet
which will work and are easily used in Access.

Ben

----------------------------------------------
Ben O'Hara "Where are all the stupid people from...
...And how'd they get so dumb?"
rockband.gif
NoFX-The Decline
----------------------------------------------
 
Hi trifest. This worked for me to export data from a query into Excel, and save it in the user's 'My Documents' folder. You can just replace "\My Documents\" with "\Desktop\".
This won't work with Win 9x/ME though. I believe using oharab's method would work better if you are trying to do it for multiple OSs.

DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel97, "QueryName", _
"C:\Documents and Settings\" & Environ("username") & "\My Documents\" & strFileName & ".xls", True,
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top