Hi All,
I have the below piece of code which runs fine on a Windows PC but I need it to run on a mac and when I run it it keeps erroring at the save file stage. The issue seems to be with the directory, this is the one I use: /Users/stroffso/desktop
Any help would be greatly appreciated
I have the below piece of code which runs fine on a Windows PC but I need it to run on a mac and when I run it it keeps erroring at the save file stage. The issue seems to be with the directory, this is the one I use: /Users/stroffso/desktop
Any help would be greatly appreciated
VBA Code:
Sub ExportNatalieAndPoppy()
Dim wb As Workbook
Dim wsNatalie As Worksheet
Dim wsControls As Worksheet
Dim saveDirectory As String
Dim natalieFileName As String
Dim selectedName As String
Dim namesArray As Variant
Dim i As Integer
Application.DisplayAlerts = False
' Set references to workbook and worksheets
Set wb = ThisWorkbook
Set wsNatalie = wb.Sheets("Summary")
Set wsControls = wb.Sheets("Controls")
' Get the save directory from Cell D18 on the Controls tab
saveDirectory = wsControls.Range("D18").Value
' Define an array of names
namesArray = Array("Natalie James", "Frank Lee")
' Loop through the names
For i = LBound(namesArray) To UBound(namesArray)
selectedName = namesArray(i)
' Set the output Excel filename
natalieFileName = selectedName & ".xlsx"
' Update the name in Cell C1
wsNatalie.Range("C1").Value = selectedName
' Copy the "Summary" tab to a new workbook
wsNatalie.Copy
ActiveWorkbook.SaveAs fileName:=saveDirectory & "\" & natalieFileName, FileFormat:=xlOpenXMLWorkbook
ActiveWorkbook.Close SaveChanges:=False
Next i
' Clean up
Set wsNatalie = Nothing
Set wb = Nothing
Application.DisplayAlerts = True
End Sub