Solved

GetSaveAsFilename & filefilter for Excel 2007/2010

Posted on 2013-02-02
4
2,753 Views
Last Modified: 2013-02-03
Regarding the code below. Instead of text files, how would you make the filefilter Excel? Both 2007/2010


TextFilename = Application.GetSaveAsFilename(InitialFileName:="New_Name", _
            filefilter:="Text Files (*.txt), *.txt", _
            Title:="Enter a name for the text file and choose a folder in which to save the text file.")

    If TextFilename <> False Then
    'Copy the worksheet containing text and number data to a new, temporary workbook.
   
        ThisWorkbook.ActiveSheet.Copy
   
        ActiveWorkbook.SaveAs Filename:=DoleFilename, FileFormat:=xlText, CreateBackup:=False
       
        ActiveWorkbook.Close SaveChanges:=False

Thanks
0
Comment
Question by:dgd1212
  • 2
  • 2
4 Comments
 
LVL 14

Expert Comment

by:Faustulus
ID: 38847852
filefilter:="Excel workbooks (*.xls*), *.xls*"
0
 

Author Comment

by:dgd1212
ID: 38847885
Perfect. Thank you.
To expand xls to include xlsx, xlsm, would that be:
filefilter:="Excel workbooks (*.xls*), *.xls*,(*.xlsx*), *.xlsx*,(*.xlsm*), *.xlsm*"
0
 
LVL 14

Accepted Solution

by:
Faustulus earned 500 total points
ID: 38848067
Not quite.
The base is xls. The asterisk stands for any letter or nothing.
So, xls* would include xlsx and xlsm as well as xls.
If you wanted to expand the filter please watch out for the comma. You can't have more than one. The comma separates the description you see from the filter you set.
Hence,
filefilter:="Excel workbooks (*.xls*), *.xls*"
has the same effect as
filefilter:="Excel workbooks, *.xls*"
If you wanted to include templates you should define
filefilter:="Excel workbooks (*.xls*)(*.xlt*), *.xls* *.xlt*"
You can also use a construct like this:-
Filter = "Excel Files (*.xls),*.xls," & _
        "Text Files (*.txt),*.txt," & _
        "All Files (*.*),*.*"
0
 

Author Closing Comment

by:dgd1212
ID: 38848674
Thank you for the solution and clarification.
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

INDEX and MATCH can be used to great effect to replace HLOOKUP and VLOOKUP as it does not have the limitation of needing the data to be sorted so that the reference value is in the first column or row. It also has the ability to perform a bi-directi…
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question