Alternative to "CreateObject" for MacOS?

BritsBlitz

New Member
Joined
Jan 10, 2014
Messages
19
I have aVBA code that works great for Windows, but need to change it for MacOS. The code creates a .txt file and writes the content from an intake form to the file. I use the following vba code to create the file and write the content to the file:

'Create the text file
Set TxtFile = CreateObject("Scripting.FileSystemObject")
Set OutTxt = TxtFile.CreateTextFile("C:\Feedback.txt", True, True)

'Write to the text file
OutTxt.Write ComboBox1.Value & ","
OutTxt.Write ComboBox2.Value & ","
OutTxt.Write ComboBox3.Value & ","
OutTxt.Close

CreateObject does not work with MacOS. Is there an alternative to CreateObject for MacOS that I can use the achieve the same as the lines above?
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
From my understanding, your issue is not the create object, it is the 'scripting.filesystemobject'. That is part of the Net Framework inside of Windows operating systems. That command, just does not exist inside of Mac. And even if you were to incorporate it, the file structure (and even the address format) is completely different as well.

There are ways around this, but it requires use of different scripts. See this post for example.

The below quote comes from that page:

On Mac, you must use the alternative syntax, something like this:

Dim a
a = FreeFile
Open "Macintosh HD:Users:nickname:Documents:myfile.txt" for For Output As #a

Print a "hello, this is output"

Close #a

I pursued the same avenue several years ago, but I ended up not venturing that path. It is much easier to program for these things when you are still developing an application, but not so easy when one is already made. I would suggest that you have a boolean check run at the beginning to verify the OS, and then have two separate codes run when needed. One for Windows, one for Mac.
 
Upvote 0

Forum statistics

Threads
1,215,385
Messages
6,124,626
Members
449,174
Latest member
Anniewonder

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