Msgbox Saving file

Zahhhaaaa

Board Regular
Joined
Jun 29, 2011
Messages
62
Hello again, could you someone give me a help with this?

I'm trying to create macro-code that when user selects commandbutton "save" on worksheet (that is linked to cell E2), msgbox will pop-up asking "save file as__E2-value__", "yes/no".

Save-button is linked to E2, where data changes daily and file is saved as data-name. One day cell E2-value can be "blaah", so file is saved as blaah, second day cell value can be "blaahblaah", so file is saved blaahblaah...etc.

Here's code I'm using;

Code:
 Sub Save()
If MsgBox("Saves file as ", vbYesNo, "Save As") = vbYes Then
ActiveWorkbook.Save
Filename = Range("E2")
ActiveWorkbook.SaveAs Filename:=Filename
End If
End Sub
´


For now, it does save the file, but when msgbox appears, filename doesn't appear on it.
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Is this what you're trying to do?
Code:
Sub Save()
  If MsgBox("Saves file as " [B][COLOR=red]& Range("E2").Value[/COLOR][COLOR=red] & "?"[/COLOR][/B], vbYesNo, "Save As") = vbYes Then
    ActiveWorkbook.Save
    Filename = Range("E2")
    ActiveWorkbook.SaveAs Filename:=Filename
  End If
End Sub
 
Upvote 0
Ruddles, I realized that code DOES work like I wanted, but it also overwrites default file.

I open my workbook named "Aaa", I do my stuff with this workbook and then I save file as name appearing on value "e2", let's say "Bbb", file is saved as "Bbb".

When I open my workbook "Aaa" again to do my stuff differently, it has all the changes I did when I was saving "Bbb", and I have to clear all the cells manually before I can start.

Is it possible that it won't overwrite previous file?
 
Upvote 0
So what do you want it to do instead? Not save at all? Prompt for a different name?
 
Upvote 0
I want it to save file with name based on e2-value, but I don't want it to overwrite default file.

Like this,

"A-file" is default, I open it, I write "fileB" on E2-value, I do some changes, write something on it and then I press "save" (commandbutton which includes this macro-code). File is saved as "fileB", but I don't want that it overwrites "A-file".

I was using this

Code:
Sub Save()
    Filename = Range("E2")
    ActiveWorkbook.SaveAs Filename:=Filename
End Sub


This one does not overwrite default file, I don't know why your code didn't work 'cuz it looks the same with msgbox.
 
Upvote 0
This is the command which saves the 'default' workbook:-
Code:
ActiveWorkbook.Save

You had it in your original code so I included it when I placed the MsgBox around it. Your latest code doesn't have that command in it.
 
Upvote 0

Forum statistics

Threads
1,224,589
Messages
6,179,744
Members
452,940
Latest member
rootytrip

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