我的宏工作得很好,但有一百万个我不想要的逗号
Sub CSVwithFormatting()
Dim fDir As String
Dim wB As Workbook
Dim wS As Worksheet
Dim fPath As String
Dim sPath As String
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = False
objExcel.DisplayAlerts = False
fPath = "path"
sPath = "path"
fDir = Dir(fPath)
Do While (fDir <> "")
If Right(fDir, 4) = ".xls" Or Right(fDir, 5) = ".xlsx" Or Right(fDir, 5) = ".xlsb" Or Right(fDir, 5) = ".xlsm" Then
On Error Resume Next
Set wB = Workbooks.Open(fPath & fDir)
csvWb = wB.Name
dd = Split(csvWb, ".")
wB.ActiveSheet.Open
Dim i As Integer
i = 0
Do While InStr((Range("A1").Value), "/") = 0 And InStr((Range("M1").Value), "/") = 0 And (i < 10)
Range("1:1").Delete
i = i + 1
Loop
Windows("Header template.xls").Activate
Rows("1:1").Select
Selection.Copy
wB.ActiveSheet.Activate
Rows("1:1").Select
Selection.Insert Shift:=xlDown
Columns("M:M").Select
Selection.Delete Shift:=xlToLeft
If Range("e2").NumberFormat = "General" Then
On Error Resume Next
Columns("E:E").Select
Selection.NumberFormat = "@"
End If
If Range("b4").Value > Range("c4").Value And Range("b6").Value > Range("c6") Then
Columns("C:C").Select
Selection.Cut
Columns("B:B").Select
Selection.Insert Shift:=xlToRight
End If
wB.ActiveSheet.SaveAs sPath & dd(0) & ".csv", xlCSV
wB.Close False
Set wB = Nothing
End If
fDir = Dir
On Error GoTo 0
Loop
End Sub
我必须在转换为csv之前在我的代码中进行大量格式化,然后在几次修剪过程之后,excels转换为但是有很多逗号