SaveAs .xls in 2007

Giordano Bruno

Well-known Member
Joined
Jan 7, 2007
Messages
1,356
I am using Excel 2007 and want to allow users of a workbook to save the file as any name they choose, but only as an xls, not an xlsm. I can't find code that works for this in Excel 2007.
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Depending on how you are saving the file maybe something like;

Code:
Fname = Application.GetSaveAsFilename( _
            InitialFileName:=Filename, _
            filefilter:="Excel (.xls), *.xls", _
            Title:="Save Excel .xls file to...")
        If Fname <> False Then
            .SaveAs Fname, xlTextMSDOS
        End If
 
Upvote 0
Thanks for that dantheman9. I'm sorry about the long delay, but the sky fell in over here and I have been sticking it back up again.

I've just tried you code, but the ".SaveAs" in the line above "End If" is blocked and I get a "Compile error: Invalid or unqualified reference"

When I apostrophe this line, the code stops on the first line with a "Run-time error 1004: Method 'GetSaveAsFilename' of object _Application failed.

Do you have any suggestions
 
Upvote 0
I would think that would be related to how you are saving the file...

It looks to me like that code needs to go in the workbook event before save.
 
Upvote 0
Hi shadow12345,

Thanks for that. I am not quite sure what you mena by "how" I am saving the file. The code is in "This Workbook" and fires when I press F12, Ctrl-S or File Save. That's when I get the error messages.
 
Upvote 0
There's no workbook specified (and the format is wrong):
Code:
ThisWorkbook.SaveAs Fname, 56
 
Upvote 0
Hello rorya,

Thanks for the contribution. But I don't know how to modify the earlier code to insert that line. What I am trying to avoid is having the name changed or the extension which must remain as ".xls" in the Excel 2007" environment.
 
Upvote 0
You replace the line that was giving you the error with the line I posted.
 
Upvote 0
Below code worked for me, you just need to set the Range to the cells you want to save or sheets.
Option also to set the Save As Diolog start location via the 'Path' option too.


Code:
Sub saveexcel()
Dim rng As Range
    Dim wb As Workbook
    Dim Fname As Variant
    Dim Path As String
 
    Set rng = Range("A1:A211") ' range of cells to save
    Set wb = Workbooks.Add
    Path = "C:\"   'Open Save As form to this location
 
    With wb
        rng.Copy
        .Worksheets(1).Range("A1").PasteSpecial Paste:=xlValues
        ' open path as set in path option box
        ChDir (Path)
        Application.DisplayAlerts = False
               Fname = Application.GetSaveAsFilename( _
            InitialFileName:="FileName", _
            filefilter:="Excel97, *.xls", _
            Title:="Save File To...")
        If Fname <> False Then
            .SaveAs Fname, 56
        End If
        .Close True
 
        End With
 
Upvote 0
rorya,
Sorry, but that gave me an error message also. I think that the original code segment is incomplete.

dantheman,
Your code goes some way to solving the problem. I don't want all the options you gave me so I have trimmed the code and it works except that it asks me to save three times.

Here is what I am using:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim wb As Workbook
Dim Fname As Variant
With wb
Application.DisplayAlerts = False
Fname = Application.GetSaveAsFilename( _
InitialFileName:="AccountIndex", _
filefilter:="Excel2003, *.xls", _
Title:="Save File To...")
If Fname <> False Then
ActiveWorkbook.SaveAs Fname, 56
End If
End With
Application.DisplayAlerts = True
End Sub

Any idea why it doesn't just ask once?
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,291
Members
452,902
Latest member
Knuddeluff

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