excel - 仅从第一个工作簿复制粘贴标题
问题描述
我想知道是否有人可以帮助我提供代码。我正在尝试仅复制和粘贴第一个工作簿的标题(它有多个工作表,所有工作簿中的所有标题/格式都相同,但数据不同)。工作簿处于循环中。我不知道如何仅从循环中的第一个工作簿中复制标题。如果有人可以帮助我,那就太好了!非常感激!
我在这里有以下代码:
Sub simpleXLSMerger()
'Just change directory path and run code. Make sure workbook is not in the same direct as files to be merge
'Remember to add the same number of worksheets same as merge files
'If code does not work, or paste blanks into worksheet, try inserting code into a new module
Dim bookList As Workbook
Dim mergeObj As Object, dirObj As Object, filesObj As Object, everyObj As Object
Dim i As Integer
Application.ScreenUpdating = False
Set mergeObj = CreateObject("Scripting.FileSystemObject")
DirectoryPath = InputBox("Directory Path")
For i = 1 To Sheets.Count
'change folder path of excel files here
Set dirObj = mergeObj.Getfolder(DirectoryPath)
Set filesObj = dirObj.Files
For Each everyObj In filesObj
Set bookList = Workbooks.Open(everyObj)
'Change number to the source sheet number you want to import (starts with 1)
Worksheets(i).Activate
Range("A2", Range("A1").End(xlDown).End(xlToRight)).Copy
'Change number to the destination sheet number you want to import to (starts with 1)
ThisWorkbook.Worksheets(i).Activate
Application.ScreenUpdating = True
'Do not change the following column. It's not the same column as above
Range("A" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
bookList.Close SaveChanges:=False
Next
Next i
MsgBox "DONE! =)"
End Sub
解决方案
推荐阅读
- ruby-on-rails - How to prevent user from accessing other user's Active Storage files
- django - Bulk insertion in django rest framework
- if-statement - 提交 Google 表单后,将电子邮件地址添加到工作表
- r - 在 dplyr 中替换 plyr::cbind.fill?
- angular - 那么如何处理更好的连锁呢?
- python - Python Flask Jinja 在另一个扩展的 html 中扩展 html
- amazon-web-services - 用于 aws-glue python shell 作业的 aws rds/mysql 安全组
- python - How to pass multiple arguments in a cleaner way in python
- docker - 如何在 docker-compose 产生的 kafka 容器上安装 kafkacat
- java - Android CalendarContract.Instances table returns old values