VBA - Simple save as .xls

Chanty

New Member
Joined
Sep 26, 2024
Messages
5
Office Version
  1. 365
Platform
  1. MacOS
Sorry if not listing this correctly, as not been on for a few years and my old account has gone.

Been trying to get a really simple bit of code to save the file I have to .xls format
No name or directory change, as save exactly as it is, but in .xls

Thought the following would work, but keep getting an error!

VBA Code:
ActiveWorkbook.SaveAs ThisWorkbook.Path & "\" & FileName.xls
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Welcome to the Board!

Try this:
VBA Code:
    Dim fName As String
    fName = Left(ActiveWorkbook.Name, InStrRev(ActiveWorkbook.Name, ".")) & "xls"
    ActiveWorkbook.SaveAs Filename:=ThisWorkbook.Path & "\" & fName, FileFormat:= _
        xlExcel8, CreateBackup:=False
 
Upvote 0
Here's a simple one if placed in ThisWorkbook module. Can be edited to save with a Sheet Name or value of a Cell.
VBA Code:
Option Explicit

Sub SaveAsXLS()
Application.DisplayAlerts = False
'Replace [Name of your File] with what you want your FileName to be (without brackets) i.e. - Birds
Me.SaveAs Filename:=Me.Path & "\[Name of your File].xls", FileFormat:=56
Application.DisplayAlerts = True
End Sub
 
Upvote 0
Welcome to the Board!

Try this:
VBA Code:
    Dim fName As String
    fName = Left(ActiveWorkbook.Name, InStrRev(ActiveWorkbook.Name, ".")) & "xls"
    ActiveWorkbook.SaveAs Filename:=ThisWorkbook.Path & "\" & fName, FileFormat:= _
        xlExcel8, CreateBackup:=False
Thanks Joe
Saved as an xls, but in an odd location - I even tried changing 'ThisWorkbook' to 'ActiveWorkbook', which saved in a less odd location, but not the one where the original file is located!
Any thoughts very much welcome - many thanks.
 
Upvote 0
Here's a simple one if placed in ThisWorkbook module. Can be edited to save with a Sheet Name or value of a Cell.
VBA Code:
Option Explicit

Sub SaveAsXLS()
Application.DisplayAlerts = False
'Replace [Name of your File] with what you want your FileName to be (without brackets) i.e. - Birds
Me.SaveAs Filename:=Me.Path & "\[Name of your File].xls", FileFormat:=56
Application.DisplayAlerts = True
End Sub
Thanks Skyybot
Getting an error on the second 'me' but also just want the file to be the same name, as will use on multiple files and will add this to the end of other code I'm using to tidy up the files, save as xls and close.
Many thanks for your help.
 
Upvote 0
I take it that the code is not in the workbook that you are trying to save. ThisWorkbook refers to the workbook that the code is in.
When you used ActiveWorkbook where did it go, ie does a "less odd location" mean ?
Is the original file on a OneDrive or Sharepoint folder ?
 
Upvote 0
I take it that the code is not in the workbook that you are trying to save. ThisWorkbook refers to the workbook that the code is in.
When you used ActiveWorkbook where did it go, ie does a "less odd location" mean ?
Is the original file on a OneDrive or Sharepoint folder ?
Hi Alex
The code is kept in the Excel 'Personal' file, so not in the actually workbook I will be working on, just hidden in the background.
Less odd location, was just in my user folder - file I am working on is in a folder in my documents folder.
 
Upvote 0
It shouldn't make any difference but since you are using a Mac and we can't replicate the issue give it a try anyway.

VBA Code:
    Dim fName As String
    fName = Left(ActiveWorkbook.FullName, InStrRev(ActiveWorkbook.FullName, ".")) & "xls"
    ActiveWorkbook.SaveAs Filename:=fName, FileFormat:= _
        xlExcel8, CreateBackup:=False
 
Upvote 0
Solution
It shouldn't make any difference but since you are using a Mac and we can't replicate the issue give it a try anyway.

VBA Code:
    Dim fName As String
    fName = Left(ActiveWorkbook.FullName, InStrRev(ActiveWorkbook.FullName, ".")) & "xls"
    ActiveWorkbook.SaveAs Filename:=fName, FileFormat:= _
        xlExcel8, CreateBackup:=False
Thanks Alex
Worked a treat!
Many thanks for your help - much appreciated.
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,196
Members
452,616
Latest member
intern444

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