Restrict File Name with getsaveasfilename

millzner

New Member
Joined
Nov 28, 2008
Messages
28
I have created an Inventory System using Excel with Userforms. I am trying to create a "Backup" function into the program where I create a new workbook and copy all my sheets to the new workbook. I am using the getsaveasfilename option to save the backup file. I set my initial file name in the "Save As" dialog box and all is working great. My question is, can I restrict the user from changing the initial file name I load? Basically I only want the user to be able to change the file path and not the file name before the save takes place.
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
You could strip the path, like:

<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> ChooseFolder()<br><SPAN style="color:#00007F">Dim</SPAN> strFolder <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN><br>    <br>    strFolder = Application.GetSaveAsFilename(InitialFilename:="WhateverYouWant.xls", _<br>                                              FileFilter:="Excel Workbooks (*.xls),*.xls")<br>    <SPAN style="color:#00007F">If</SPAN> <SPAN style="color:#00007F">Not</SPAN> strFolder = "False" <SPAN style="color:#00007F">Then</SPAN><br>        strFolder = Left(String:=strFolder, _<br>                         Length:=Len(strFolder) - _<br>                                 (Len(strFolder) - _<br>                                    InStrRev(strFolder, "\", -1, vbTextCompare)))<br>    <SPAN style="color:#00007F">Else</SPAN><br>        MsgBox "something esle, like bailing the sub..."<br>    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br></FONT>

...or if xl2000, you could use an API:

http://www.vbaexpress.com/kb/getarticle.php?kb_id=246

...or if 2003 or 07, I think maybe FolderPicker dialog. (I'm at home and on 2000 - and a bad memory...)

Hope this helps,

Mark
 
Upvote 0
GTO - Using Excel 2000. Just ran a quick test using the API and should be able to do exactly what I want. Thanks for the help.
 
Upvote 0

Forum statistics

Threads
1,214,585
Messages
6,120,399
Members
448,957
Latest member
Hat4Life

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