gpt4 book ai didi

vba - 在 Excel 文件夹内的所有文件上添加一列

转载 作者:行者123 更新时间:2023-12-04 14:27:45 25 4
gpt4 key购买 nike

我在一个文件夹中有 250 个不同的 excel 文件(具有相同的布局),列为 AF。我需要在列 G 上添加一个新列。传统方法是打开每个文件并在 G 处添加新列。是否有任何使用 Excel 宏或任何其他工具来完成此操作的简单过程?

最佳答案

This link帮助过我。以下是我的解决方案,它有效:

Sub LoopThroughFolder()

Dim MyFile As String, Str As String, MyDir As String, Wb As Workbook
Dim Rws As Long, Rng As Range
Set Wb = ThisWorkbook
'change the address to suite
MyDir = "C:\Users\dell\Desktop\Folder1\" 'Your Directory
MyFile = Dir(MyDir & "*.xlsx") 'Your excel file extension
ChDir MyDir
Application.ScreenUpdating = 0
Application.DisplayAlerts = 0

Do While MyFile <> ""
Workbooks.Open (MyFile)
Range("G1").Value = "NewColumn" 'New Column Name
ActiveWorkbook.Save
ActiveWorkbook.Close True
MyFile = Dir()
Loop

End Sub

关于vba - 在 Excel 文件夹内的所有文件上添加一列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42097710/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com