物联网软件开发价钱
物联网软件开发公司 你的位置:物联网软件开发价钱 > 物联网软件开发公司 >

物联网软件开发公司 四个“宽阔文献合并”场景的vba代码

发布日期:2024-11-05 05:45    点击次数:157

一、合并责任表(合并归并个责任簿中的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

[扫码或长按二维码关注公众号,物联网app开发获取更多精准推荐]

三、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

本站仅提供存储职业,总共本色均由用户发布,如发现存害或侵权本色,请点击举报。

下一篇:没有了

Powered by 物联网软件开发价钱 @2013-2022 RSS地图 HTML地图

Copyright Powered by365站群 © 2013-2024 云迈科技 版权所有