反差 英文 四个“无数文献合并”场景的vba代码
一、合并责任表(合并吞并个责任簿中的100个责任表反差 英文,这100个责任表表头王人相通)
色吧性爱Sub 合并责任表() Dim ws As Worksheet Dim wsMerged As Worksheet Dim rng As Range Dim lastRow As Long Dim lastCol As Long Dim i As Long ' 创建一个新的责任表用于存放合并后的数据 Set wsMerged = ThisWorkbook.Worksheets.Add wsMerged.Name = '合并后的责任表' ' 遍历责任簿中的统共责任表 For Each ws In ThisWorkbook.Worksheets ' 跳过合并后的责任表 If ws.Name <> '合并后的责任表' Then ' 赢恰现时责任表的终末一转和终末一列 lastRow = ws.Cells(ws.Rows.Count, 1).End(xlUp).Row lastCol = ws.Cells(1, ws.Columns.Count).End(xlToLeft).Column ' 复制现时责任表的数据到合并后的责任表 Set rng = ws.Range(ws.Cells(1, 1), ws.Cells(lastRow, lastCol)) rng.Copy Destination:=wsMerged.Cells(wsMerged.Cells(wsMerged.Rows.Count, 1).End(xlUp).Row 1, 1) End If Next ws ' 删除合并后的责任表中的空缺行 lastRow = wsMerged.Cells(wsMerged.Rows.Count, 1).End(xlUp).Row For i = lastRow To 1 Step -1 If Application.WorksheetFunction.CountA(wsMerged.Rows(i)) = 0 Then wsMerged.Rows(i).Delete End If Next iEnd Sub
二、合并责任簿
Sub MergeWorkbooks() Dim wbDest As Workbook Dim wbSource As Workbook Dim wsSource As Worksheet Dim rngSource As Range Dim rngDest As Range Dim lastRow As Long Dim filePath As String ' 假定目的责任簿依然翻开,况兼名为'MergedData.xlsx' Set wbDest = Workbooks('MergedData.xlsx') ' 遍历文献夹中的统共Excel文献 filePath = 'C:\Path\To\Your\Files\' ' 替换为你的文献夹旅途 fileName = Dir(filePath & '*.xlsx') Do While fileName <> '' If fileName <> 'MergedData.xlsx' Then ' 排斥目的责任簿 ' 翻开源责任簿 Set wbSource = Workbooks.Open(filePath & fileName) ' 遍历源责任簿中的每个责任表 For Each wsSource In wbSource.Sheets ' 假定数据从A1初始 Set rngSource = wsSource.Range('A1').CurrentRegion ' 找到目的责任簿中对应责任表的终末一转 With wbDest.Sheets(wsSource.Name) lastRow = .Cells(.Rows.Count, 'A').End(xlUp).Row 1 End With ' 复制并粘贴到目的责任簿的对应责任表 rngSource.Copy Destination:=wbDest.Sheets(wsSource.Name).Cells(lastRow, 1) Next wsSource ' 关闭源责任簿,不保存改动 wbSource.Close False End If ' 赢得下一个文献名 fileName = Dir() LoopEnd Sub
三、100个word文档合并为1个
Sub 合并Word文档() Dim fso As Object Dim f As Object Dim wdDoc As Object Dim wdApp As Object ' 建筑Word期骗 Set wdApp = CreateObject('Word.Application') ' 翻开一个新的Word文档 Set wdDoc = wdApp.Documents.Add ' 建筑文献系统对象 Set fso = CreateObject('Scripting.FileSystemObject') ' 界说文献夹旅途和文献名 Dim folderPath As String folderPath = 'C:\旅途\Word文档\' ' 改动为你的文献夹旅途 Dim fileNames As Variant fileNames = Split(fso.GetFile(folderPath & '*.docx').Path, '\') ' 合并文档 Dim i As Integer For i = 0 To UBound(fileNames) If InStr(fileNames(i), '.docx') > 0 Then ' 翻开要合并的文档 Set wdDocTemp = wdApp.Documents.Open(folderPath & fileNames(i)) ' 复制执行到新文档 wdDocTemp.Range.Copy wdDoc.Range ' 关闭临时文档 wdDocTemp.Close False End If Next i ' 保存合并后的文档 wdDoc.SaveAs folderPath & '合并后的文档.docx' ' 关闭Word期骗 wdApp.Quit Set wdApp = Nothing Set fso = NothingEnd Sub
四、把100个ppt中统共幻灯片合并到一个ppt中去
Sub 合并PPT() Dim 目的PPT As Presentation Dim 源PPT As Presentation Dim 文献旅途 As String Dim 文献名 As String Dim i As Integer ' 建筑目的PPT文献旅途 文献旅途 = 'C:\合并的PPT\' ' 改动为你的目的文献夹旅途 ' 创建新的PPT文献 Set 目的PPT = Presentations.Add(文献旅途 & '合并后的PPT.pptx') ' 轮回遍历统共PPT文献 For i = 1 To 100 ' 构建源PPT文献称呼 文献名 = 'C:\合并的PPT\' & 'PPT' & i & '.pptx' ' 翻开源PPT文献 Set 源PPT = Presentations.Open(文献名) ' 将源PPT中的统共幻灯片复制到目的PPT For Each Slide In 源PPT.Slides 目的PPT.Slides.Insert(After:=目的PPT.Slides.Count).ShapeRange.CopyFromSlide(Slide.ID) Next Slide ' 关闭源PPT文献 源PPT.Close Next i ' 保存合并后的PPT文献 目的PPT.Save ' 计帐 Set 源PPT = Nothing Set 目的PPT = Nothing ' 完成辅导 MsgBox 'PPT文献合并完成!'End Sub
本站仅提供存储处事,统共执行均由用户发布,如发现存害或侵权执行,请点击举报。