Dear Sir or Madam:
My name is Robert, and I am a middle school math teacher who wants to EXCLUDE specific worksheet tabs from being converted to CSV files. The specific worksheet tabs to be EXCLUDED are XLSX, Math Grades Messenger, Directory Paths, POW Grader and POW Grader Student List. Please refer to the following macro:
My name is Robert, and I am a middle school math teacher who wants to EXCLUDE specific worksheet tabs from being converted to CSV files. The specific worksheet tabs to be EXCLUDED are XLSX, Math Grades Messenger, Directory Paths, POW Grader and POW Grader Student List. Please refer to the following macro:
Code:
Sub SaveEachTabAsCSV()
Dim strMyPath As String
Dim wsMySheet As Worksheet
Dim intFileCount As Integer
With Application
.ScreenUpdating = False
.DisplayAlerts = False
End With
strMyPath = Sheets("Directory Paths").Range("A1") 'Path to save the individual tabs as CSV files. Change to suit but don't forget trailing backslash!!
'Add trailing backslash if user hasn't
If Right(strMyPath, 1) <> "\" Then
strMyPath = strMyPath & "\"
End If
'Ensure the 'strMyPath' directory exists
If Dir(strMyPath, vbDirectory) = "" Then
MsgBox "The path """ & strMyPath & """ doesn't exist!!" & vbNewLine & "Please check it and try again.", vbCritical
Exit Sub
End If
For Each wsMySheet In ThisWorkbook.Sheets
If wsMySheet.Visible = xlSheetVisible Then
intFileCount = intFileCount + 1
wsMySheet.Copy
ActiveWorkbook.SaveAs Filename:=strMyPath & wsMySheet.Name & ".csv", FileFormat:=xlCSV
ActiveWorkbook.Close
End If
Next wsMySheet
With Application
.DisplayAlerts = True
.ScreenUpdating = True
End With
MsgBox intFileCount & " CSV file(s) have now been saved in the """ & strMyPath & """ directory.", vbInformation
End Sub
Last edited by a moderator: