Hi
What I'm trying to do is write a small program that copies a file from a USB to another directory so a program already installed on the computer can load this data.
Usually copying files from one directory into another wouldn't be an issue.
Code:Module Module1 Sub Main() Dim SpecialFolder As String Dim fs As Object Dim oldPath As String, newPath As String oldPath = "H:\" 'Folder file is located in newPath = "H:\folder" 'Folder to copy file to fs = CreateObject("Scripting.FileSystemObject") fs.CopyFile(oldPath & "\" & "January2009.txt", newPath & "\" & "January2009.txt") 'This file was an .xls file fs = Nothing End Sub End Module
Unfortunately the program were using loads information from the specific user application settings directory
So on my computer this is C:\Documents and Settings\Alastair\Application Data\DPlot
but on your computer this might be C:\Documents and Settings\*****\Application Data\DPlot
Hence i cant hardcode the destination directory for the files I'm copying
I have tried googling this with very ineffective results as it is a reasonably specific problem. However every single peace of software that you install on you computer will usually access the "Application Settings" folder and copy information into without experiencing any problems, hence this is defiantly possible I just don't know the correct way to do it.
The only thing that I have been able to find that look remotely is the function
Environment.GetFolderPath(SpecialFolder.ApplicationData)
However I'm having difficulties using this in VBA as it immediately asks me to declare what "SpecialFolder" is.
If possible i would also like to change the code i have written so it just loads January2009.txt from the "root directory" of the USB rather than having to specify H:\ because if i put the USB in someone elses computer this could change to G:\ and then it wouldn't work.
Any ideas?




Reply With Quote