国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

VBA腳本語言測試Excel宏定義處理文件拷貝

2024-07-21 23:03:55
字體:
來源:轉載
供稿:網友
VBA腳本語言測試Excel宏定義處理文件拷貝



  1. '指定文件目錄復制工具(可用戶基于svn版本管理的項目做增量發布用途使用)   
  2. '作者:許果   
  3. '日期:2010-11-26   
  4. Sub copyfiles()   
  5. On Error GoTo errorflag   
  6. '指定目標文件的行號   
  7. Dim i As Integer   
  8. '指定目標文件的目錄的長度變量   
  9. Dim j As Integer   
  10. '目錄名稱數組,生成目標文件的過程目錄名字列表   
  11. Dim directoryNameArray() As String   
  12. '指定的目標文件部分文件路徑名稱   
  13. Dim relativeFilePath As String   
  14. '臨時目錄名稱   
  15. Dim tempDirectoryName As String   
  16. For i = 0 To Cells(3, 2) - 1   
  17.     tempDirectoryName = ""   
  18.     '獲得指定的目標文件的路徑名稱   
  19.     relativeFilePath = Cells(4 + i, 2)   
  20.     If relativeFilePath = "" Then   
  21.         Exit For   
  22.     End If   
  23.     relativeFilePath = Replace(relativeFilePath, "/""/")   
  24.     directoryNameArray = Split(relativeFilePath, "/")   
  25.     '如果拷貝的目標文件件路徑的目錄不存在,就依次建立相應的目錄文件   
  26.     For j = 0 To UBound(directoryNameArray) - 1   
  27.         tempDirectoryName = tempDirectoryName & "/" & directoryNameArray(j)   
  28.         If Dir(Cells(2, 2) & tempDirectoryName, vbDirectory) = "" Then   
  29.            MkDir Cells(2, 2) & tempDirectoryName   
  30.         End If   
  31.     Next j   
  32.        
  33.     '設置需要復制的源文件路徑和目標路徑   
  34.     Dim destinationFileFullPath As String   
  35.     Dim sourceFileFullPath As String   
  36.     sourceFileFullPath = Cells(1, 2) & tempDirectoryName & "/" & directoryNameArray(j)   
  37.     destinationFileFullPath = Cells(2, 2) & tempDirectoryName & "/" & directoryNameArray(j)   
  38.    
  39.     '復制文件   
  40.     FileCopy sourceFileFullPath, destinationFileFullPath   
  41. Next i   
  42. MsgBox "指定的文件目錄已復制完畢"   
  43. GoTo finished   
  44. Exit Sub   
  45. errorflag:   
  46. MsgBox sourceFileFullPath & (i + 4)   
  47. finished:   
  48. End Sub   

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 延庆县| 洱源县| 潼关县| 杭锦旗| 伊金霍洛旗| 宜昌市| 咸宁市| 景德镇市| 南投市| 隆安县| 高雄县| 灵山县| 泸溪县| 滕州市| 上栗县| 章丘市| 渭源县| 北碚区| 大田县| 固镇县| 哈密市| 黄冈市| 佛教| 广丰县| 和硕县| 乾安县| 双流县| 紫金县| 临潭县| 临西县| 同德县| 夏邑县| 江孜县| 大英县| 花垣县| 静宁县| 镇江市| 沙洋县| 南澳县| 濉溪县| 太仆寺旗|