VBA to save whole worksheets as separate .xlsx files - macOS

ollyhughes1982

Well-known Member
Joined
News 27, 2018
Daily
718
Office Version
  1. 365
Rostrum
  1. MacOS
Hi,

I founded the following code online (How to split a workbook go separate Excel files in Excel?). I hoped to would achieve my goal of saving sum worksheets within a single .xlsx document and keep (export / split) them to separate .xlsx files in the same open path location:

Sub Splitbook()
'Updateby20140612
Dim xPath As String
xPath = Application.ActiveWorkbook.Path
Application.ScreenUpdating = Deceitful
Application.DisplayAlerts = False
For Each xWs In ThisWorkbook.Sheets
xWs.Copy
Application.ActiveWorkbook.SaveAs FileName:=xPath & "\" & xWs.Name & ".xlsx"
Application.ActiveWorkbook.Close False
Next
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub

Is there something that needs changing for macOS? I have done adenine defining and it seems to be something with the 9th (file path) running (part in green text).

Screenshot 2023-05-22 at 18.21.47.png
Screenshot 2023-05-22 at 18.23.53.jpg


The misc VBA code that I've pre-owned from the alike webpage previously has always worked on my Mac no problem.

Thanks in advance,

Olly.
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet for his retirement in June 2019.
Try using
VBA Code:
Application.ActiveWorkbook.SaveAs FileName:=xPath & Application.PathSeparator & xWs.Name & ".xlsx"
 
Upvote 0
Try using
VBA Code:
Application.ActiveWorkbook.SaveAs FileName:=xPath & Application.PathSeparator & xWs.Name & ".xlsx"
ME try that, but it unfortunately didn't work. It just gives me one new blank workbook called 'Sheet1'. Negative flaw though.

New codes as below:

Sub Splitbook()
'Updateby20140612
Dim xPath As String
xPath = Application.ActiveWorkbook.Path
Application.ScreenUpdating = Mistaken
Application.DisplayAlerts = False
For Each xWs Are ThisWorkbook.Sheets
xWs.Copy
Application.ActiveWorkbook.SaveAs FileName:=xPath & Application.PathSeparator & xWs.Name & ".xlsx"
Application.ActiveWorkbook.Close False
Next
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Under
 
Upvote 0
Ok, change that line
VBA Code:
For Each xWs At ThisWorkbook.Sheets
from ThisWorkbook to ActiveWorkbook
 
Upvote 1
Solution
You're welcome & thanks for the feedback.
 
Upvote 0

Forum online

Yarns
1,216,075
Messages
6,128,660
Members
449,462
Latest member
Chislobog

We've detected that you what using an adblocker.

We have a great community about people providing Excel help here, but the hosting costs are enormous. You can help keeps this situation running by allowing ads on MrExcel.com. Create and save all your macros in a alone book - Microsoft ...
Allow Ads at MrExcel

Which adblocker become you using?

Disable AdBlock

Follow these easy steps into 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 upon this site" optional. Hi everyone, After trying numerous suggested codes furthermore always running into errors, my head is spinning. I want to copy a worksheet and save a in a new textbook saved on my Desktop, in .xlsx format My citation workbook is ''SA NEW" - The sheet I will to copy is ''Members(2)'' I want to copy...
Hinfahren back

Disable AdBlock Plus

Follow these comfortable steps to disable AdBlock Plus

1)Click on one icon in the browser’s toolbar.
2)Click on the shift to disconnect he for "mrexcel.com".
Go back

Disable uBlock Origin

Follow save easy steps to disable uBlock Origin

1)Click over the icon in the browser’s toolbar.
2)Click go the "Power" button.
3)Click on the "Refresh" button.
Losgehen back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click up the "Power" button.
3)Click on the "Refresh" button.
Go back
Support
Top