Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi All,
I have a Qlikview App that tracks code files, I want to use a macro to copy the file I have selected to another folder.
At the moment I can delete the file, open the file or Open the Directory.
I want to copy the 1 file I have selected and place the copied file in another folder
I have copied files before from the script, but I need to have a button option to run a macro and copy the file based on the [Full Path] I have selected
Thanks
Alan
This may help
From Blogg.sigma.se
Dim
fso
' create a global copy of the filesystem object
Set
fso = CreateObject(
"Scripting.FileSystemObject"
)
TemplatePath = fso.GetAbsolutePathName(
"."
) &
"\qvw.template"
<a id=
"ctl00_FullRegion_PC_148_1_EditForm_MainBody_ctl00_resize"
class=
"mceResize"
onclick=
"return false;"
href=
"javascript:;"
></a>
' WScript.Echo TemplatePath
' Call the RecurseFolders routine
' Takes one argument - in this case, the Path of the folder to be searched
RecurseFolders
"."
' echo the job is completed
' WScript.Echo "Completed!"
Sub
RecurseFolders(sPath)
With
fso.GetFolder(sPath)
if .SubFolders.Count > 0
Then
For
Each
Folder
In
.SubFolders
if Left(Folder.Name, 1) <>
"."
Then
If
InStr(1, folder.Path,
"-prj"
) <> 0
Then
' Copy and rename template to create empty qvd file next to prj folder
If
fso.FileExists(TemplatePath)
Then
fso.CopyFile TemplatePath, Replace(folder.Path ,
"-prj"
,
".qvw"
), OverWriteExisting
End
If
End
If
' Recurse to check for further subfolders
RecurseFolders folder.Path
End
If
Next
End
if
End
With
End
Sub
Hi,
Thanks, but I don't think does what I need
Regards
Alan
Can anyone help with this
I used below script. You just need to replace string to dynamically generate path.
SUB CopyFileSub
rFile = "C:\source.txt"
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile = fso.GetFile(rFile)
MyFile.Copy ("C:\copy.txt")
END SUB
and more advance version ( copy to user desktop) :
SUB CopyFileSub
rFile = "C:\source.txt"
Set fso = CreateObject("Scripting.FileSystemObject")
Set WshShell = CreateObject("WScript.Shell")
strDesktop = WshShell.SpecialFolders("Desktop")
Set MyFile = fso.GetFile(rFile)
wFile = strDesktop & "\copy.txt"
MyFile.Copy (wFile)
END SUB
Thanks Pawel,
I have tried this based on what you gave me
However I keep getting an error saying "file not found"
"Full Path" is the location and filename of the source I want to copy to my temp folder
I can advice following steps:
1. Make sure file is accessible from your computer.
2. Good diagnostic practice is to display "Full Path" in some textbox to check if they are properly generated.
3. Copy final path to windows explorer address bar to see if file will open.
I write below code to check file existence:
if fso.FileExists(rFile) then
Set MyFile = fso.GetFile(rFile)
wFile = strDesktop &"\"& fName
MyFile.Copy (wFile)
call msgbox("File has been saved to your desktop.",0,"DONE")
else
call msgbox("No file to Save",0,"Error")
end if
Thanks Pawel,
I will have a look
Regards
Alan
Now i see that you use only folder Path to copy your file i think you need to provide path with filename as argument to MyFile.Copy function.
Use
MyFile.Copy("C:\temp\file.jpg")
instead of
MyFile.Copy("C:\temp\")
Regards
Pawel