mardi 17 juillet 2018

Excel VBA How to prevent user from hitting cancel in msoFileDialogSaveAs

I am very new to VBA and I am creating a template for my boss. I want to force users to "save as" so that they don't overwrite the template. In other words, I'd like to disable the cancel button when the save as dialog box pops up.

Here is my code:

Dim fPth As Object
Set fPth = Application.FileDialog(msoFileDialogSaveAs)

With fPth
    .InitialFileName = CTAPath
    .InitialFileName = CTAName & "_CAP DATA"
    .Title = "Save with your CTA file"
    .InitialView = msoFileDialogViewList
    .FilterIndex = 2
    If .Show = -1 Then
        .Execute

    End If
End With

I'm thinking I should create an ELSE statement within the IF statement but I can't figure out what it should be. I've tried searching and I'm not coming up with any solutions.

Thank you!

Aucun commentaire:

Enregistrer un commentaire