Solved

GetSaveAsFilename & filefilter for Excel 2007/2010

Posted on 2013-02-02
4
2,837 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
copy same as above data 18 37
I need help with an EXCEL Nested formula. 5 21
Date Formatting on Userform Print 5 26
VBA working with shapes 6 11
Drop Down List with Unique/Distinct Values (Part II - ComboBox or ListBox and Data Validation List Bonus!) David Miller (dlmille) Intro This article focuses on delivering unique, sorted lists to list objects (e.g., ComboBox, ListBox) and Dat…
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

856 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