Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

copy and paste macro

Hi,

how to write macro code for copying the images(.bmp) from one folder(source folder) and paste into another folder(destination folder).

Any idea on this ?

Thanks in  advance.

5 Replies
m_woolf
Master II
Master II

Try something like this:

Const OverWrite = False

Dim fso, srcFiles, destPath

Set fso = CreateObject("Scripting.FileSystemObject")

srcFiles = “c:\Test\Alarm\*.*”

destPath = “c:\Test\AlarmHistory”

If fso.FolderExists (destPath) = False Then

     fso.CreateFolder (destPath)

End If

fso.CopyFile srcFiles, destPath

Not applicable
Author

Hi,

That is working fine.

Can we provide for user chooice to select his destination i.e; not providing destination location to directly.

That mean a computer window should popup and user will choose his/her loaction in the local system.

Can we provide this type of code in macro ?

Thanks in advance.

CELAMBARASAN
Partner - Champion
Partner - Champion

Hi,

     Check with attached text file.

    BrowseFolder("",True);

Celambarasan

m_woolf
Master II
Master II

sub pickfolder
     Set objShell = CreateObject("Shell.Application")
     Set objFolder = objShell.BrowseForFolder(0, "Example", 1, "c:\Programs")
     If objFolder Is Nothing Then
          Wscript.Quit
     End If
     msgbox "folder: " & objFolder.title & " Path: " & objFolder.self.path
end sub

Not applicable
Author

Hi

i tried below lines its working but in this code itself i am trying to provide the user selectable destination.

what i needs to change in below code to acheive it ?

Sub CopyPasteImages

Dim sOriginFolder, sDestinationFolder, oFSO

Set oFSO = CreateObject("Scripting.FileSystemObject")

Set vLensInspectionImageNames=ActiveDocument.Variables("vLensInspectionImageNames")

Set vImageSourcePath=ActiveDocument.Variables("vImagesLocation")

Set vImageDestinationPath=ActiveDocument.Variables("vImagesDestination")

ArrFields = split(vLensInspectionImageNames.GetContent.String, ",")

For Each fIndex in ArrFields

sOriginFolder = vImageSourcePath.GetContent.string&fIndex

sDestinationFolder = vImageDestinationPath.GetContent.string&fIndex

if oFSO.fileExists(sOriginFolder) then

    oFSO.CopyFile sOriginFolder, sDestinationFolder

end if 

Next

End Sub

please can you share your ideas on this.