How Do You Exclude Specific Tabs from Being Converted into CSV Files?

njpamdnc

New Member
Joined
Feb 16, 2019
Messages
42
Office Version
  1. 2007
Platform
  1. Windows
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:

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:

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
How about
Code:
For Each wsMySheet In ThisWorkbook.Sheets
   If wsMySheet.Visible = xlSheetVisible Then
      Select Case wsMySheet.Name
         Case "XLSX", "Math Grades Messenger", "Directory Paths", "POW Grader", "POW Grader Student List"
         Case Else
            intFileCount = intFileCount + 1
            wsMySheet.Copy
            ActiveWorkbook.SaveAs FileName:=strMyPath & wsMySheet.Name & ".csv", FileFormat:=xlCSV
            ActiveWorkbook.Close
      End Select
   End If
Next wsMySheet
 
Upvote 0
Hello Again...I don't mean to be disrespectful, but I really like the macro I provided for you due to the fact it automatically converts multiple worksheets into CSV files, and it automatically replaces previous unwanted versions of the CSV files. Your macro prompted me to save or not save each of my 25 worksheets whereas the macro I have been using never prompts me. The program runs uninterrupted until the process has ended. Is there a way you can embed/modify the code for my macro in order to prevent the following 5 worksheets from being converted?: "XLSX", "Math Grades Messenger", "Directory Paths", "POW Grader", and "POW Grader Student List". I have to convert Excel files to CSV files in order to upload student grades into my school district's online gradebook. During the uploading process, I would like to keep the folder I use for Excel to CSV file conversions to remain clutter free of unwanted CSV-converted files.

Robert


How about
Code:
For Each wsMySheet In ThisWorkbook.Sheets
   If wsMySheet.Visible = xlSheetVisible Then
      Select Case wsMySheet.Name
         Case "XLSX", "Math Grades Messenger", "Directory Paths", "POW Grader", "POW Grader Student List"
         Case Else
            intFileCount = intFileCount + 1
            wsMySheet.Copy
            ActiveWorkbook.SaveAs FileName:=strMyPath & wsMySheet.Name & ".csv", FileFormat:=xlCSV
            ActiveWorkbook.Close
      End Select
   End If
Next wsMySheet
 
Upvote 0
Just replace this part of your code
Code:
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 the code I supplied.
 
Upvote 0
It worked...Thank You!!!

Just replace this part of your code
Code:
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 the code I supplied.
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,159
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top