# Microsoft Office Application Help - Excel Help forum > For Other Platforms(Mac, Google Docs, Mobile OS etc) >  >  MAC VBA Fails to save and close named workbook

## codebasher

I have a Excel VBA to anlayse SFDC data that has been running on Windows for years and I need to port it across to Excell 2011 for MAC, due to the number of users choosing MAC laptops.

Most of the code /userforms , opening files and calculations all work fine. The only issue I have is trying to save a named Workbook, any method i try results in an error and exception. I end up with a lot of working file therefore left open.

Attempt to close open files either by direct filename reference or <file_pointer> always fails....even though the file is valid and open in MAC Excel.Workbooks("Extract.xls").CloseWorkbooks("Extract.xls").Close savechanges := FalseWorkbooks(ref_fn_index("Extract.xls")).Close


======Example code tried ========

Workbooks("Extract.xls").Close

Workbooks("Extract.xls").Close savechanges := False

Workbooks(ref_fn_index("Extract.xls")).Close


Public Function ref_fn_index(enq_file As String) As Integer
'=== Find reference ptr of open workbook filename for MAC restriction====
Dim i As Integer
Dim file_seen As Boolean

file_seen = False
ref_fn_index = -1
For i = 1 To Workbooks.count
    If LCase(Workbooks(i).name) = LCase(enq_file) Then
        file_seen = True
        ref_fn_index = i
        Exit Function
    End If
Next i
'==== Catch error case ===
If Not file_seen Then MsgBox "Unable to find current workbook", vbCritical, "File I/O Eror"
End Function

----------


## codebasher

Additional Info : Directory_path 

In case MAC VBA wants  full directory path, I also tried to pre-pend the current directory to the filename, which made no difference.

Note : MAC directory uses ":" rather than "\" in Windows

----------


## Norie

How are you opening the files?

----------


## codebasher

Open by this

Workbooks("Extract.xls").Open

I only wrote the ref_fn_ptr function to see if filename was seen by MAC VBA and it is - returning "3", when debuging I see the workbook.name matching "Extract.xls"  in that function. I'm just unable to close a workbook by "Name".

By testing I found Active.Workbook.close works...but I don't want to keep swaping Active.workspace -hence want to use the "Name" Close.

----------


## JosephP

presumably you mean



```
Please Login or Register  to view this content.
```


and



```
Please Login or Register  to view this content.
```


since neither of your examples are valid code. I suggest you simply store a reference to the workbook and use that to close it



```
Please Login or Register  to view this content.
```


although I can't see why your code would fail-do you get an error message?

----------


## codebasher

Sadly have to return to this topic, as more MAC users and pressure not to run a Windows Virtual machine on MAC.. hence refreshing theme of Workbooks.Close on MAC VBA for Excel.

I tried a separate sub-routine for closing after reading other threads on same topic

Public Sub MAC_close_book(ByVal book_name As String, ByVal storedata As Boolean)
'==== Attempt to safely close workbook without MAC error ======

If storedata Then Workbooks(book_name).Save
      Workbooks(book_name).Saved = True
      Application.DisplayAlerts = False
      Workbooks(book_name).Close False
End Sub


The only line that throws an error is the final close statement which would indicate that MAC VBA knows the file reference is valid and able to update it. The error message is always  :

Method of _workbook Object failed

----------

