`

VBA脚本语言测试Excel宏定义处理文件拷贝

阅读更多
'指定文件目录复制工具(可用户基于svn版本管理的项目做增量发布用途使用)
'作者:许果
'日期:2010-11-26
Sub copyfiles()
On Error GoTo errorflag
'指定目标文件的行号
Dim i As Integer
'指定目标文件的目录的长度变量
Dim j As Integer
'目录名称数组,生成目标文件的过程目录名字列表
Dim directoryNameArray() As String
'指定的目标文件部分文件路径名称
Dim relativeFilePath As String
'临时目录名称
Dim tempDirectoryName As String
For i = 0 To Cells(3, 2) - 1
    tempDirectoryName = ""
    '获得指定的目标文件的路径名称
    relativeFilePath = Cells(4 + i, 2)
    If relativeFilePath = "" Then
        Exit For
    End If
    relativeFilePath = Replace(relativeFilePath, "/", "\")
    directoryNameArray = Split(relativeFilePath, "\")
    '如果拷贝的目标文件件路径的目录不存在,就依次建立相应的目录文件
    For j = 0 To UBound(directoryNameArray) - 1
        tempDirectoryName = tempDirectoryName & "\" & directoryNameArray(j)
        If Dir(Cells(2, 2) & tempDirectoryName, vbDirectory) = "" Then
           MkDir Cells(2, 2) & tempDirectoryName
        End If
    Next j
    
    '设置需要复制的源文件路径和目标路径
    Dim destinationFileFullPath As String
    Dim sourceFileFullPath As String
    sourceFileFullPath = Cells(1, 2) & tempDirectoryName & "\" & directoryNameArray(j)
    destinationFileFullPath = Cells(2, 2) & tempDirectoryName & "\" & directoryNameArray(j)

    '复制文件
    FileCopy sourceFileFullPath, destinationFileFullPath
Next i
MsgBox "指定的文件目录已复制完毕"
GoTo finished
Exit Sub
errorflag:
MsgBox sourceFileFullPath & (i + 4)
finished:
End Sub

分享到:
评论
1 楼 fruitking 2010-11-29  
单步执行F8的快捷健

相关推荐

    excel sheet拷贝

    给定的代码为一个VBA宏(Visual Basic for Applications),主要用于实现Excel工作簿中Sheet的拷贝操作。此宏能够遍历指定目录下的所有`.tmp`扩展名的工作簿,并将每个工作簿中的所有Sheet内容复制到当前活动工作簿...

    网管教程 从入门到精通软件篇.txt

    可用数据文件(能被Excel 97打开);Oracle 8.1.x表格空间文件 DBX:DataBearn图像;Microsoft Visual FoxPro表格文件 DCT:Microsoft Visual FoxPro数据库容器 DCU:Delphi编译单元文件 DCX:Microsoft Visual...

    ArcGIS二次开发编程实例

    - 在ArcMap中启用VBA开发环境的具体步骤包括:启动ArcMap后,通过“工具”菜单选择“宏”,然后创建新的宏文件或编辑现有宏文件来实现特定功能。 - **1.1.2 如何在VB环境中利用ArcObjects组件开发ActiveX DLL:** ...

    C++程序员需具备知识.pdf

    - 掌握`#define`宏定义的用法,注意其与变量定义的区别。 - **数值与指针** - **数组定义与初始化**:熟悉数组的基本操作,包括定义、初始化、遍历等。 - **多维数组**:了解多维数组的概念及使用方法。 - **...

Global site tag (gtag.js) - Google Analytics