Macro works on Windows but doesnt work on Mac

moustafaabdelhady

New Member
Joined
Feb 4, 2019
Messages
5
I have created a macro to copy from one cell to another in another workbook.
Although works perfectly fine on windows, it doesnt work on Mac
I am not a pro, can anybody help to get it work on Mac please

Here is the Macro :

Code:
Sub Make_New_File()
'
'   Make_New_File() Macro
Application.ScreenUpdating = False


Dim Path As String
Dim filename As String
Dim filetoopen As String
Dim filetoopen2 As String
Dim Wbk As Workbook
Dim Ws As Worksheet




    Set sFolder = ThisWorkbook.Sheets("Database").Range("MainFolder")
    Set FValidation = ThisWorkbook.Sheets("Database").Range("FolderValidation")


    filetoopen = ThisWorkbook.Sheets("Database").Range("NewCustomerFile")
    filetoopen2 = ThisWorkbook.Sheets("Database").Range("NewCustomerFile2")


    If Dir(sFolder) <> (FValidation) Then
        Workbooks.Open (filetoopen2)


        'open if the folder from the main desktop
        Workbooks("Natuurelle.xlsb").Sheets("Klant | Patient Registratie").Activate
        Range("C2").Select
        Range("C" & Rows.Count).End(xlUp).Offset(0, 8).Select
        Selection.Copy




        Windows("Patient map sjabloon.xlsb").Activate
        Sheets("Patient map").Select
        Range("D7").Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        Application.CutCopyMode = False


        Application.DisplayAlerts = False
        ActiveWorkbook.CheckCompatibility = False
        Path2 = ThisWorkbook.Sheets("Database").Range("CustomersFilesArchive")
        filename = Range("C1").Value & " - " & Range("D1")
        ActiveWorkbook.SaveAs filename:=Path2 & filename & ".xlsb", FileFormat:=xlExcel12, CreateBackup:=False
    
Else
       Workbooks.Open (filetoopen)
    
       'open if the folder from the other desktop
       Workbooks("Natuurelle.xlsb").Sheets("Klant | Patient Registratie").Activate
       Range("C2").Select
       Range("C" & Rows.Count).End(xlUp).Offset(0, 8).Select
       Selection.Copy


       Windows("Patient map sjabloon.xlsb").Activate
       Sheets("Patient map").Select
       Range("D7").Select
       Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
       :=False, Transpose:=False
       Application.CutCopyMode = False
  
       Application.DisplayAlerts = False
       ActiveWorkbook.CheckCompatibility = False
       Path2 = ThisWorkbook.Sheets("Database").Range("CustomersFilesArchive2")
       filename = Range("C1").Value & " - " & Range("D1")
       ActiveWorkbook.SaveAs filename:=Path & filename & ".xlsb", FileFormat:=xlExcel12, CreateBackup:=False


End If


MsgBox "Klant map is gemakt voor:" _
& "  " & Sheets("Patient map").Range("D1").Value


Application.ScreenUpdating = True
End Sub
 
Last edited by a moderator:

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)
Please explain what "doesn't work" means.



  • Does the code run?
  • Does it run but do nothing?
  • Does it produce error messages? If so, what do the messages say?
  • Does it produce unexpected/wrong results? If so, how do the results differ from what you expect?
  • Does it hang?



What is the value of ThisWorkbook.Sheets("Database").Range("MainFolder") in both the Windows and Mac versions?
 
Upvote 0
thank you so much for the quick reply

Answering your questions:

  • Does the code run? yes
  • Does it run but do nothing? it bugs at a certain point
  • Does it produce error messages? If so, what do the messages say? yes it does, Runtime error9 subscript out of range.
  • Does it produce unexpected/wrong results? If so, how do the results differ from what you expect? no results
  • Does it hang?
It stops at the Line 21
Error.jpg
Error2.jpg
where it says: Windows("Patient map sjabloon.xlsb").Activate


Error screen shot attached
 
Upvote 0
Which workbook does Windows("Patient map sjabloon.xlsb") refer to?

Is it the workbook the code is in, the one you open in the code or another open workbook?
 
Upvote 0
By 'second' workbook do you mean the workbook open here?

Code:
        Workbooks.Open (filetoopen)
Or the one being opened here?
Code:
        Workbooks.Open (filetoopen)
Whichever it is you should create a reference to it when you open it and then use that in subsequent code.
 
Upvote 0
Thanks again for your reply,
yes it is for the second file, I have declared it and the reference is in the cell in the main Workbook

Dim filetoopen As String
filetoopen = ThisWorkbook.Sheets("Database").Range("NewCustomerFile")
what I saw is that the macro opens the other workbook ("Patient map sjabloon.xlsb") but it accept the orders after that...
I dont know what should I change to make the code readable by Excel on Mac
 
Upvote 0
This is getting the name/path to the file.
Code:
filetoopen = ThisWorkbook.Sheets("Database").Range("NewCustomerFile")

What I mean is to create an object reference to the workbook when you open like this.
Code:
Set wb = Workbooks.Open(filetoopen)

If you had that code then you could use the reference wb whenever you need to refer to the workbook later in the code.

That would avoid having to refer to the workbook by name which is the most likely reason for the problem you are having.
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,241
Members
452,622
Latest member
Laura_PinksBTHFT

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