VBA to export to any desktop

Neilster

Registered User.
Local time
Today, 15:41
Joined
Jan 19, 2014
Messages
218
Hi Guys,

I have this code below which works fine and sends an Excel spread sheet to the users desktop.

DoCmd.SetWarnings False

DoCmd.OpenQuery "QryBristolj"

DoCmd.SetWarnings True
Dim strFullyQualifiedFilename As String

strFullyQualifiedFilename = "C:\Users\User\Desktop\End Of Month.xlsx"

DoCmd.TransferSpreadsheet acExport, , "QryBristolj", strFullyQualifiedFilename

MsgBox "File has been exported to your desktop" & strFullyQualifiedFilename

End Sub
However I want to be able to use this code to work for any client and therefore need a universal bit of VBA in the below line of code to work on any PC without having to ask the client for their path file.

strFullyQualifiedFilename = "C:\Users\User\Desktop\End Of Month.xlsx"
Hope that makes sense and can anyone help.

Cheers :D
 
You'll need an environmental variable. Google VBA Environ function
 
Nice one! I've sorted it using the 'VBA Environ function'

Thanks for your help. (-:
 
For the benefit of the thousands that are going to read this post in the future: what was the specific solution?
 
It would look like "C:\Users\" & Environ("USERNAME") & "\Desktop\End Of Month.xlsx"
 
No.

=Environ("Public") & "\Desktop\End Of Month.xlsx"
 

Users who are viewing this thread

Back
Top Bottom