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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copy File Help

Status
Not open for further replies.

mdex

Technical User
Nov 28, 2011
10
GB
Morning all,

I'm trying to use access to copy a file from a network location to local machine.

I can copy the file no problem with absolute path names but want to use environment variables for network users.

OldName = "\\cottonwood\SomeExample.xls"
NewName = "D:\Documents and Settings\%USERNAME%\My Documents\SomeExample2.xls"
retval = 0
Dim objFSO As Object
Set objFSO = CreateObject("Scripting.FileSystemObject")
retval = objFSO.CopyFile(OldName, NewName, True)
Set objFSO = Nothing
MsgBox "Copy/paste complete"

For the life of me I cannot figure it out.

I realise the new name string cannot have %username% like it is but just copied the code in as an example.

Also tried this way...

Dim afterpath As String

afterpath = Environ(appdata)

OldName = "\\cottonwood\SomeExample.xls"
NewName = afterpath

Just can't get my head around the Environ or if it's even the correct way of doing it?

Any help appreciated.
 
Code:
NewName = "D:\Documents and Settings\" & Environ$("USERNAME") & _
          "\My Documents\SomeExample2.xls"
 
Cheers Golom.

Thought Environ was the way to go.

mdex
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top