Solved

GetSaveAsFilename & filefilter for Excel 2007/2010

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Dealing with unintended Excel Active-X resizing quirks (VBA code simulates "self correction") David Miller (dlmille) Intro Not everyone is a fan of Active-X controls in spreadsheets (as opposed to the UserForm approach, the older Form controls …
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…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
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.

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now