我试图在 excel 中创建一个 vba 脚本,以便将文件夹中所有 xlsx 文件的内容复制到 cvs 文件中。
我用作帮助:http ://www.ozgrid.com/VBA/2007-filesearch-alternative.htm
并创建了以下脚本:
Sub CopySameSheetFrmWbs()
Dim wbOpen As Workbook
Dim wbNew As Workbook
Const strPath As String = "C:\test\"
Dim strExtension As String
'Comment out the 3 lines below to debug
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
On Error Resume Next
ChDir strPath
strExtension = Dir("*.xlsx")
Do While strExtension <> ""
Set wbOpen = Workbooks.Open(strPath & strExtension)
Set wbNew = Workbooks.Add
wbNew.SaveAs Filename:="C:\test\copiedFile", FileFormat:=xlCSV
wbOpen.Sheets(Sheets.Count).Copy
wbNew.Sheets(Sheets.Count).PasteSpecial
strExtension = Dir
Loop
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
On Error GoTo 0
End Sub
我想我只是不明白,这就是它不起作用的原因。此代码创建一个空的 csv 文件,并在每次运行脚本时创建一些奇怪的工作簿。
你能帮我么?