这个问题不应该很复杂。我有一个大文件夹,里面有200个单独的文件夹。现在,每个文件夹都有一个Excel表格。我想在控制文件夹(200旁边)的vba文件中有一些代码,它可以迭代200个文件夹并更改每个excel文件中的一位数据。我发现目录的东西和文件夹迭代,但我无法在这里和那里合并它们,我需要一些简单的帮助。如何编辑多个excel文件,每个文件位于一个文件夹中的不同文件夹中
我的代码目前是:`子的button1_Click()
Dim wb As Workbook
Dim ws As Excel.Worksheet
Dim iIndex As Integer
Dim strPath As String
Dim strFile As String
'Get the directories
strPath = "C:\Users\generaluser\Desktop\testing main folder\"
strFile = Dir(strPath, vbDirectory)
'Loop through the dirs
Do While strFile <> ""
'Open the workbook.
strFileName = Dir(strPath & strFile & "New Microsoft Excel Worksheet.xlsm", vbDirectory)
'Open the workbook.
Set wb = Workbooks.Open(Filename:=strPath & strFile & "\" & strFileName, ReadOnly:=False)
'Loop through the sheets.
Set ws = Application.Worksheets(1)
'Do whatever
'Close the workbook
wb.Close SaveChanges:=True
'Move to the next dir.
strFile = Dir
Loop
末次 `
请帮@MatthewD
如果你没有向我们展示你编写的代码以使它工作,那么这很复杂。从概念上讲,它可能很简单,就是这样,但是没有代码,我们没有办法可以梦想为项目框架着色所需的具体细节。如果您发布了您尝试过的代码,我们可以帮助您进行编辑。没有多少人愿意为你做。 –
好吧,我不确定从哪里开始。我知道代码需要先抓住主文件夹,然后遍历每个文件夹。然后对于我知道的每个文件夹,需要制作工作簿,然后调用第一张工作表,然后进行必要的编辑。它只是一个循环和一些代码,但我不知道如何调用原始文件夹的目录,然后循环其余的所有内容。 –