尽pipe循环不循环也不做
为了进一步永远不再做任何手册,我做了一个it.xlsm,你必须放在一个文件夹与一个特定的文件,必须处理。
这个it.xslm有三个模块:
Masterfile – 重命名C中的类别
– 在C中为每个类别创build一个工作表
将这些工作表保存为.xslx。 这会导致/ Departement文件夹中有8个新文件
Littlefiles
– 在E中重新命名
为每个类别制定标签
– 清理空列。
占位符
使用数据应用主文件打开.xls
打开由masterfiles创build的所有文件
使选项卡和清理空列。
占位符代码:
Sub OpenBigFile() Dim wb As Workbook Dim ws As Worksheet Dim Lastrow As Long 'open main file, apply masterfile moduke Set wb = Workbooks.Open(ThisWorkbook.path & "\Depositformulier (Reacties).xlsx") Call masterfile.total wb.Close SaveChanges:=True End Sub
这工作正常。
Sub OpenAllFiles() Dim wb As Workbook Dim myPath As String Dim myFile As String myPath = ThisWorkbook.path & "\" & "Departement" & "\" myFile = Dir(myPath & "*.xlsx") Do While Len(Filename) > 0 DoEvents Set wb = Workbooks.Open(myPath & myFile, True, True) Call LittleFiles.total wb.Close False myFile = Dir Loop End Sub
在这里,我发现自己有问题。 我试着重写很多次,使用很多例子,但总是似乎卡在Set wb = Workbooks.Open(Filename:=myPath & myFile)
我究竟做错了什么? 你需要我的Littlefiles代码吗?
此外,一般来说,即使在另一个工作簿处于活动状态(即ActiveWorkbook)的情况下,“ThisWorkbook”始终会引用this.xlm是否正确?
谢谢一堆
这是我的尝试,我认为这样会很难出错,因为你将有已经存储的文件的完整path:
Sub OpenAllFiles() 'create an array Dim myFiles As Variant ReDim myFiles(500) myPath = ThisWorkbook.Path If Right(myPath, 1) <> "\" Then myPath = myPath & "\" End If 'search for at least 5 files in the folder specified above, add the entire path to the array While myCount < 5 If Dir(myPath & "*.xlsm") <> "" Then potentialFileToLoad = Dir(myPath & "*.xlsm") While potentialFileToLoad <> "" myFiles(myCount) = myPath & potentialFileToLoad myCount = myCount + 1 potentialFileToLoad = Dir Wend End If Wend 'change size of array to ammount of files found ReDim Preserve myFiles(myCount - 1) For Each ii In myFiles '(Insert Open, Run code, close code here) Workbooks.Open (ii), True, True Call LittleFiles.Total ActiveWorkbook.Close Next ii End Sub
尝试类似这样的事情
path = "path2folder" & "\" 'this is fairly important and probably why your code breaks?_ you cant add the backslash like you do above Filename = Dir(path & "*.xl??") Do While Len(Filename) > 0 DoEvents Set wbk = Workbooks.Open(path & Filename, True, True) 'add your code wbk.Close False Filename = Dir Loop