Missing an if issue

sassriverrat

Well-known Member
Joined
Oct 4, 2018
Messages
655
I messed up an if here and was hoping someone could check it for me

Code:
Private Sub Save_As()'Creates the SaveAs "Current Voyage" on the Noon Sheet


    Dim Path1 As String
    Dim Path2 As String
    Dim Path3 As String
    Dim myfilename As String
    Dim fpathname As String
    Dim resp As Integer
    Dim name As String
    
    With Worksheets("Notes")
    Path1 = .Range("O16")
    name = .Range("N4")
    Path2 = .Range("O18")
    Path3 = .Range("U16")
    End With
    
    myfilename = Path2
    fpathname = Environ("Userprofile") & "\" & Path1 & "\" & Path3 & "\"
    
    If ActiveWorkbook.name = "Master Voyage Report.xlsm" Then
        ActiveSheet.EnableCalculation = False
    
        resp = MsgBox("You are trying to save the " & myfilename & " to:" & vbCrLf & fpathname & myfilename & ".xlsm", vbYesNo, name)
        If resp = vbYes Then
            If Dir(fpathname, vbDirectory) = "" Then MkDir (fpathname)
                Else: ActiveWorkbook.SaveAs Filename:=fpathname & myfilename & ".xlsm", FileFormat:=xlOpenXMLWorkbookMacroEnabled
            End If
                'Application Closer
            If Workbooks.Count > 1 Then
                ActiveWorkbook.Close
            Else: Application.Quit
            End If
        ElseIf vbNo Then
            Exit Sub
        ElseIf vbCancel Then
            Exit Sub
        End If
    ElseIf ActiveWorkbook.name = myfilename Then
        ActiveWorkbook.Save
        'Application Closer
                If Workbooks.Count > 1 Then
                    ActiveWorkbook.Close
                Else: Application.Quit
                End If
    Else: ActiveWorkbook.Save
        'Application Closer
                If Workbooks.Count > 1 Then
                    ActiveWorkbook.Close
                Else: Application.Quit
                End If
    End If
End Sub
 
It's the other way round
Len=0
Dir=""
Not sure if there is any benefit to one method over the other.

Interesting....so I just pulled a small section out of my code. It error'd earlier, kicking me because I had = 0 instead of as you see it.

Code:
resp = MsgBox("You are trying to save the " & myfilename & " to:" & vbCrLf & fpathname & myfilename & ".xlsm", vbYesNo, name)
        If resp = vbYes Then
            If Dir(fpathname, vbDirectory) = "" Then
                MkDir (fpathname)
                ActiveWorkbook.SaveAs Filename:=fpathname & myfilename & ".xlsm", FileFormat:=xlOpenXMLWorkbookMacroEnabled
            Else
                ActiveWorkbook.SaveAs Filename:=fpathname & myfilename & ".xlsm", FileFormat:=xlOpenXMLWorkbookMacroEnabled
            End If
 
Upvote 0

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Also, what would stop me if I had a
Kill Filename
from allowing me to delete a file? Debug says permission denied?
 
Upvote 0
No problem, was just answering your question on what would stop you killing the file.
Are you still having issues with the save? If yes I will try and look at it when I get in but I am working for 12 hours today so might not feel like it then.
 
Upvote 0
seems to be working now. It's particularly odd that it's inconsistent...i couldn't replicate the problem. I appreciate you looking into it for me!
 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,307
Members
452,633
Latest member
DougMo

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