code not working at the end if/with

dannyok90

Board Regular
Joined
Aug 30, 2016
Messages
115
The last part of this code is not working, its saying end with without with and I cant workout why? any ideas guys? :) happy new year!

Code:
Public Sub SaveAsC3()
    Dim ThisFile As String, DoF As String
    ThisFile = Range("C3").Value
    DoF = Range("V2").Value
    fName = "T:\V-Task\V0000+\200+\V0297\Shared\PSR Submissions\" & ThisFile & " " & "PSR" & " " & DoF
    ActiveWorkbook.Save
    On Error GoTo err
    Application.DisplayAlerts = False
    If (MsgBox("Are you sure you want to submit this PSR?", vbYesNo, "Decision")) = vbYes Then
        With ActiveWorkbook
            .SaveAs Filename:=fName, FileFormat:=xlOpenXMLWorkbookMacroEnabled
            Application.ExecuteExcel4Macro "show.toolbar(""Ribbon"",TRUE)"
            ActiveWindow.DisplayWorkbookTabs = True
            Application.DisplayAlerts = False
            If Workbooks.Count < 2 Then
            Application.Quit
 Else
 ThisWorkbook.Close
        End With
    End If
err:
    Application.DisplayAlerts = False
End Sub
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Looks like you're missing an End If

Code:
            If Workbooks.Count < 2 Then
                Application.Quit
            Else
                ThisWorkbook.Close
            End If

HTH :)
 
Upvote 0
Nah bother - It can throw you sometimes "End With without With" when it really means "If without End If", used to catch me out when I first started out. Always best to check for both when it gives this kind of error :)
 
Upvote 0
yeah I was switching the end if and the end with round and still getting nothing, thanks for the education my friend!
 
Upvote 0

Forum statistics

Threads
1,224,828
Messages
6,181,209
Members
453,023
Latest member
alabaz

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