我在一个文件夹内有 250 个不同的 excel 文件(具有相同的布局),其中包含列A
to F
。我需要在列上添加新列G
。传统的方法是打开每个文件并在以下位置添加新列G
。有没有使用 Excel 宏或任何其他工具的简单过程来完成此任务?
这个链接 http://www.xlorate.com/vba-examples.html#Loop%20Through%20Folder帮助过我。以下是我的解决方案,有效:
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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)