Excel, VBA : auto save to CSV with semicolon« Wróć do listy pytań

Excel, VBA : auto save to CSV with semicolon
Wysłane przez mrmucha
Zadane przez 25/09/2015 15:24
0

Use Local:=True – it’s depend on your system regional settings and separator field

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
Sub SaveWorksheetsAsCsv()
 
Dim WS As Excel.Worksheet
Dim SaveToDirectory As String
 
Dim CurrentWorkbook As String
Dim CurrentFormat As Long
 
CurrentWorkbook = ThisWorkbook.FullName
CurrentFormat = ThisWorkbook.FileFormat
SaveToDirectory = "C:\test\"
For Each WS In ThisWorkbook.Worksheets
    Sheets(WS.name).Copy
    ActiveWorkbook.SaveAs Filename:=SaveToDirectory & "questions.csv", FileFormat:=xlCSV, Local:=True
 
    ActiveWorkbook.Close savechanges:=False
    ThisWorkbook.Activate
Next
 
Application.DisplayAlerts = False
ThisWorkbook.SaveAs Filename:=CurrentWorkbook, FileFormat:=CurrentFormat
Application.DisplayAlerts = True
 
End Sub
Sub SaveWorksheetsAsCsv()

Dim WS As Excel.Worksheet
Dim SaveToDirectory As String

Dim CurrentWorkbook As String
Dim CurrentFormat As Long

CurrentWorkbook = ThisWorkbook.FullName
CurrentFormat = ThisWorkbook.FileFormat
SaveToDirectory = "C:\test\"
For Each WS In ThisWorkbook.Worksheets
    Sheets(WS.name).Copy
    ActiveWorkbook.SaveAs Filename:=SaveToDirectory & "questions.csv", FileFormat:=xlCSV, Local:=True

    ActiveWorkbook.Close savechanges:=False
    ThisWorkbook.Activate
Next

Application.DisplayAlerts = False
ThisWorkbook.SaveAs Filename:=CurrentWorkbook, FileFormat:=CurrentFormat
Application.DisplayAlerts = True

End Sub
Wysłane przez mrmucha
Odpowiedziane 25/09/2015 15:26