仅复制文件夹VBA的第一个文件 [英] Copy only the first file of a folder VBA

查看:55
本文介绍了仅复制文件夹VBA的第一个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现了如何使用VBA将所有文件从一个文件夹复制到另一个文件夹.

I have found out how to copy all the files from a folder to another folder using VBA.

我唯一找不到的就是如何只能移动文件夹的前三项.

The only thing I can't find is how that I can only move the first three items of a folder.

我为每个项目拍摄三张照片,并且为每个项目使用Excel工作表创建另一个文件夹.因此,它应该移动(或复制)三张图片,然后移动到下三张图片并执行相同的操作(但使用另一个文件夹).

I'm taking three pictures per item and for every item I create another folder using an excel sheet. So it should move (or copy) three pictures, and then move to the next three and do the same (but with another folder).

我唯一找不到的是如何仅从文件夹中选择前三个项目.

the only thing I can't find is how to select only the three first items from a folder.

我现在使用.copyfile方法.

I use the .copyfile method at the moment.

Dim ESN, FromPath, ToPath, LastRow, PN, FileToCopy, MyFile, i, k,     NumberOfFiles As Integer, Module
LastRow = ActiveWorkbook.ActiveSheet.Range("E" & Rows.Count).End(xlUp).Row + 1
 NumberOfFiles = InputBox("How many parts do you want to enter?", "# of parts?")

Dim FSO As Object
Set FSO = CreateObject("scripting.filesystemobject")
'Select all files
FileToCopy = "*.*"


ESN = ActiveWorkbook.ActiveSheet.Range("A1").Value
ESN = Right(ESN, 6)
For k = NumberOfFiles To 1 Step -1
'path toekennen
Module = ActiveWorkbook.ActiveSheet.Range("B" & LastRow - k).Value
PN = ActiveWorkbook.ActiveSheet.Range("G" & LastRow - k).Value
FromPath = "D:\DCIM\100OLYMP\"
ToPath = "U:\tmo\Checklist Engine Records\LEAP 1A\PHOTOS\" & Module & _
"\" & ESN & "_" & PN & "\"
MyFile = Dir(FromPath & "\*.JPG")

'folder creeeren als deze niet bestaat
If FSO.folderexists(ToPath) = False Then
FSO.createfolder ToPath
End If
    For i = 0 To 2
    FSO.movefile Source:=FromPath & FileToCopy, Destination:=ToPath
    MyFile = Dir
    Next i
Next k`

谢谢!卡瓦鲁.

推荐答案

myfile=dir("c:\yourpath" & "\*.jpeg")
i=1
for i = 1 to 3
 ' your commands
myfile=Dir
next i

这可能会帮助您...将此代码添加到您的函数或子程序中...

this might help you...add this code in your function or sub...

这篇关于仅复制文件夹VBA的第一个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆