|
以下代码是把把"d:\aa"目录中所有excel文件打开,进行格式化,另存到其它的目录中,本来很好,由于需要把另存的目录建一个第个字段中文件夹存入其中,加了紫色部分的代码,加了以后处理也没问题,就是不能进行循环了,提示“b=dri无效的调用或参数”,为什么会出现这种情况呢,是在建立文件夹操作之后,b的变量进行变化了?
sub dy()
Dim b
'Application.ScreenUpdating = False
'Application.DisplayAlerts = False
If Dir("d:\ftp\", vbDirectory) = "" Then
MkDir "d:\ftp\"
End If
If Dir("d:\ftp\查询\", vbDirectory) = "" Then
MkDir "d:\ftp\查询\"
End If
If Dir("D:\ftp\查询\查询结果\", vbDirectory) = "" Then
MkDir "D:\ftp\查询\查询结果\"
End If
b = Dir("d:\aa\*.xls")
Do While b <> ""
Workbooks.Open Filename:="d:\aa\" & b
MsgBox b
aa = ActiveSheet.Cells(ActiveSheet.UsedRange.Rows.Count, 1).Value
bb = Mid(aa, 7, (Len(aa) - 7))
mm = "D:\ftp\查询\查询结果\" & bb & "\"
If Dir(mm, vbDirectory) = "" Then
MkDir mm
End If
Workbooks(b).Activate
Call whc
Workbooks(b).Activate
abc = mm & Left(ActiveWorkbook.Name, Len(ActiveWorkbook.Name) - 4) & "-" & Trim(bb) & ".xls"
Workbooks(b).Activate
ActiveWorkbook.Save
ActiveWorkbook.SaveAs Filename:=abc
ActiveWorkbook.Close False
Kill "d:\aa\" & b
b = Dir
Loop
MsgBox "d:\aa文件里没有文件!"
MsgBox "全部处理完毕!"
End Sub
|
|