Sekory
Sekory

Reputation: 143

VBA Dialogs.Show doesn't display warning message

Have Excel (2010 in my case but I think it will be the same also in other versions) with two workbooks. Save first one with name "1.xlx" (example) via Save As dialog. Save second one with the same name "1.xlx" to different location. Excel will not allow it with following warning message:

"You cannot save this workbook with the same name as another open workbook or add-in. Choose a different name, or close the other workbook or add-in before saving."

So far so good. But my problem is that I need to invoke dialog via VBA. I am using following code:

Sub test()

Application.Dialogs(XlBuiltInDialog.xlDialogSaveAs).Show

End Sub

Now I am trying to save second workbook (with the same name to different location) but when I click to 'Save' button nothing happen, no warning message. If I wouldn't know what is wrong it would be very difficult to tell. I didn't change any setting (there is nothing as DisplayAlerts set to true or so). Any idea how make SaveAs dialog invoked via VBA to display similar warnings?

Upvotes: 0

Views: 447

Answers (2)

nirmalraj17
nirmalraj17

Reputation: 494

Can you try with the below code on starting on your code.

Application.DisplayAlerts = True

Upvotes: -1

Dick Kusleika
Dick Kusleika

Reputation: 33145

I'm not sure why that doesn't give you an error, but it doesn't me either. If you use Application.FileDialog, you can get that error.

Sub testts()

    With Application.FileDialog(msoFileDialogSaveAs)
        .Show
        .Execute
    End With

End Sub

Or you could use GetSaveAsFileName and check the names of all the open workbooks and generate the error yourself.

Upvotes: 2

Related Questions