I don't quite get how the code works for commonDialogs
This is what I have so far, and it works like I want it to, except for if the user hits the cancel button.
On Error GoTo errhandler
CommonDialog1.Filter = ".txt"
CommonDialog1.FileName = "MyFile.txt"
If Right(CommonDialog1.FileName, 4) <> ".txt" Then
FileToSave = CommonDialog1.FileName & ".txt"
FileToSave = CommonDialog1.FileName
I thought that when the user hit the cancel button, the error handler would run, but it doesn't.
The if statements are so if the user types in a filename without the extension, then it will automatically add the extension to it before it saves, just like other windows programs. Maybe there's a different way to do that??
The problem is if the user hits cancel, then it still runs the rest of the code, instead of going to the error handler like I thought it would.
I already tried stuff like:
If FileToSave = "" then exit sub
but the dialog filename keeps its value instead of being = to ""
What am I doing wrong?