Results 1 to 6 of 6

Thread: How Do You Exclude Specific Tabs from Being Converted into CSV Files?
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    New Member
    Join Date
    Feb 2019
    Posts
    12
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

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

    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 Fluff; Jun 15th, 2019 at 11:55 AM. Reason: Code tags

  2. #2
    MrExcel MVP
    Moderator
    Fluff's Avatar
    Join Date
    Jun 2014
    Location
    Chippenham
    Posts
    28,403
    Post Thanks / Like
    Mentioned
    471 Post(s)
    Tagged
    47 Thread(s)

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

    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
    - Posting Data try one of these tools
    - Posting guidelines, forum rules and terms of use
    - Read the FAQs

    Running Office 365 on Win 10

  3. #3
    New Member
    Join Date
    Feb 2019
    Posts
    12
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

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

    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


    Quote Originally Posted by Fluff View Post
    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

  4. #4
    MrExcel MVP
    Moderator
    Fluff's Avatar
    Join Date
    Jun 2014
    Location
    Chippenham
    Posts
    28,403
    Post Thanks / Like
    Mentioned
    471 Post(s)
    Tagged
    47 Thread(s)

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

    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.
    - Posting Data try one of these tools
    - Posting guidelines, forum rules and terms of use
    - Read the FAQs

    Running Office 365 on Win 10

  5. #5
    New Member
    Join Date
    Feb 2019
    Posts
    12
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

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

    It worked...Thank You!!!

    Quote Originally Posted by Fluff View Post
    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.

  6. #6
    MrExcel MVP
    Moderator
    Fluff's Avatar
    Join Date
    Jun 2014
    Location
    Chippenham
    Posts
    28,403
    Post Thanks / Like
    Mentioned
    471 Post(s)
    Tagged
    47 Thread(s)

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

    You're welcome & thanks for the feedback
    - Posting Data try one of these tools
    - Posting guidelines, forum rules and terms of use
    - Read the FAQs

    Running Office 365 on Win 10

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •