Detecting change in Save As filename before hitting OK

Lassebasse

New Member
Joined
Oct 23, 2014
Messages
16
Hi everyone,

Maybe a cryptic Title but I'll explain:

I Use "Application.Dialogs(xlDialogSaveAs).Show(filename)" (containing prompted filename) to open Dialog window Save As.
Now, I want to detect if that filename in an way is changed before hitting "OK" to save (actually I want to prevent/stop any change of the filename).

Can I lock the filename to the prompted one, or at least exit code if any change is made to the filename before hitting "OK"?


Thank you in advance!


Regards
lassebasse
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Hi frank,

No, I'm afraid that doesn't help me. After the user klicks a button, another box appears (to fill in). After that the SaveAs Dialog opens with the prompted filename which I want to lock or at least detect change in, before the user klicks "OK".

Any other suggestions?

/Lassebasse
 
Upvote 0
What happens previous to the Save As dialog is not really important (a textBox with preset values appears, whithin maybe 1 value (outof 2) is changed, or not).

Then this Dialog opens:

Code:
If Application.Dialogs(xlDialogSaveAs).Show(filename) = False Then
    Exit Sub
End If

... in which I think I need an "ElseIf (prompted name changes)"
OR some way of locking the prompted name to prevent any change.

/Lassebasse
 
Upvote 0
Thank you for your post, Youngdand.

From what I understand that code locks path to a certain folder to save in.
I need 1) to open saveas Dialog where the prompted filename is locked (user not being able to change it), but 2) user must be able to choose folder to save in.
 
Upvote 0
How about, allowing the saveas to proceed, and using an after save event to get the path of the saved file, and write the correctly named file back to that path. (you could then possibly delete the file they saved).
<code class="lang-vb hljs vbnet"><code class="lang-vb hljs vbnet">
Code:
</code>Private Sub Workbook_AfterSave(ByVal Success As Boolean) 
If Success Then 

your code

End If 
End Sub<code class="lang-vb hljs vbnet">
</code></code>
 
Upvote 0
Code:
Private Sub Workbook_AfterSave(ByVal Success As Boolean)
Dim Sl As String
Dim newfname As String
If Success Then
Sl = ThisWorkbook.Path
newfname = ("test")
Do While ThisWorkbook.FullName <> Sl & "\" & newfname & ".xlsm"
ThisWorkbook.SaveAs Filename:=Sl & "\" & newfname, FileFormat:=52
Loop
End If
End Sub
 
Upvote 0
Code:
Private Sub Workbook_AfterSave(ByVal Success As Boolean)
Dim Sl As String
Dim newfname As String
If Success Then
Sl = ThisWorkbook.Path
newfname = ("test")
Do While ThisWorkbook.FullName <> Sl & "\" & newfname & ".xlsm"
ThisWorkbook.SaveAs Filename:=Sl & "\" & newfname, FileFormat:=52
Loop
End If
End Sub


Thank you for your answer.
I've never used "after-save"-event, interesting ... :), but I think this "after-saveAs-Work" would be something that this requires.

Is newfname the prompted filename of my choice?

So, your code first let the user save the file even with a changed promted filename, correct?

... and then loop through the "saved-in-folder" to save it yet again, but now with the prompted filename?
So far, there is 2 new saved files in the chosen folder?

(Is FileFormat:=52 = ".xlsm"?)


You mentioned something about deleting the first file, if the user saved one with a changed filename ...?
I think I would need that, how would that look in code? Could it be done using code, when I don't know the name of file?



TY very much for your time and effort!

Please bare with me if I don't get it! :)
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,262
Members
452,627
Latest member
KitkatToby

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