• Running a code from a userform Submit button switches my sheet

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Running a code from a userform Submit button switches my sheet

    Author
    Topic
    #1772425

    Hello,

    A submit button to save a specific/non-active worksheet as an excel file. The submit button simply calls the module below. after i’m i save the sheet (ws3) the sheet suddenly shows up. is there a way to keep this sheet out of sight. i don’t want it to show at the end (after saving the file or cancelling saving the file).

    Thank you in advance.

    Code:
    Sub saveCOasExcel()
    
    
        Dim WB As Workbook, InitFileName As String, fileSaveName As String
         
        
        Dim ws3 As Worksheet
    
    
    Set ws3 = Worksheets(“Change Order”)
    
    
       With Application
            .ScreenUpdating = False
            .EnableEvents = False
        End With
    
    
         ws3.Visible = xlSheetVisible
      
        ws3.Copy
        
        InitFileName = ThisWorkbook.Path & “Change Order# ” & Format(Date, “yyyy-mm-dd”)
         
        Sheets(“Change Order”).Copy
         ‘ or below for more than one sheet
         ‘ Sheets(Array(“Output”, “Sheet2”, “Sheet3″)).Copy
         
        Set WB = ActiveWorkbook
         
        fileSaveName = Application.GetSaveAsFilename(InitialFileName:=InitFileName, _
        filefilter:=”Excel files , *.xlsx”)
         
        With WB
            If fileSaveName  “False” Then
                 
                .SaveAs fileSaveName
                .Close
            Else
                .Close False
                Exit Sub
            End If
        End With
      
      
         With Application
            .ScreenUpdating = True
            .EnableEvents = True
        End With
    
    ws3.Visible = xlSheetHidden
    
    
    End Sub
    
    Reply To: Running a code from a userform Submit button switches my sheet

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: