Alternative to "CreateObject" for MacOS?

BritsBlitz

New Member
Joined
Jan 10, 2014
Messages
34
Office Version
  1. 365
Platform
  1. Windows
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

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
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,224,819
Messages
6,181,153
Members
453,021
Latest member
Justyna P

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