Vba For Directory Path In Excel 2011 For Mac

This Excel tutorial explains how to use the Excel CHDIR statement with syntax and examples.

Cannot open file using Excel 2011 because 'The file path is too long' Hello, I am unable to open many of my files using Excel 2011 easily because apparently their file paths are too long.

Description

The Microsoft Excel CHDIR statement allows you to change the current directory or folder.

The CHDIR function is a built-in function in Excel that is categorized as a File/Directory Function. It can be used as a VBA function (VBA) in Excel. Sharpdevelop alternatives for mac os. As a VBA function, you can use this function in macro code that is entered through the Microsoft Visual Basic Editor.

Syntax

The syntax for the CHDIR statement in Microsoft Excel is:

Parameters or Arguments

path
The path that you'd like to set the current directory to.

Returns

The CHDIR statement does not return a value, but rather changes the current directory or folder on the current drive.

Note

  • If you need to change drives, try using the CHDRIVE statement first.

Applies To

  • Excel for Office 365, Excel 2019, Excel 2016, Excel 2013, Excel 2011 for Mac, Excel 2010, Excel 2007, Excel 2003, Excel XP, Excel 2000

Example (as VBA Function)

The CHDIR statement can be used in VBA code in Microsoft Excel.

Let's look at some Excel CHDIR statement function examples and explore how to use the CHDIR statement in Excel VBA code:

For example:

In this example, the current directory would now be changed to C:instructions.

Excel mac vba open file
I have a workbook that I am trying to get to work on both the Windows & Mac versions of Excel. So far so good on Windows. I'm having a problem on Excel 2011 for Mac right now, and can't seem to figure out why. Google searching has not turned up a solution.
One of the things my workbook does is it creates a new workbook, and I want to save that new workbook to a specific folder on the Mac. That folder (on my Mac) is:
El Capitan:mattc:Library:Containers:com.microsoft.Excel:Data:Test Folder:
All of those folders exist. In fact, my code will create the 'Test Folder' folder if it does not already exist.
My code will create the new workbook, but when it tries to save it, I run into the problem. The line of code causing the error is:
For the sake of my testing, here is what the variables are:
FileNameAndPath = 'El Capitan:mattc:Library:Containers:com.microsoft.Excel:Data:Test Folder:TestFile.xlsx'
FilePassword = 'password2019'
On Excel 2019 for Mac, this works perfectly. On Excel 2011, I am getting this error:
Run-time error '1004':
Microsoft Excel cannot access the file 'El Capitan:mattc:Library:Containers:com.microsoft.Excel:Data:Test Folder:88544000'. There are several possible reasons:
- The file name or path name does not exist.
- The file you're trying to open is being used by another program. Close the document in the other program, and try again.
- The name of the workbook you're trying to save is the same as the name of another document that is read-only. Try saving the workbook with a different name.
I remember seeing this error once before on Windows, when I was trying to write a file inside the 'Program Files' folder. I assumed I did not have permission to access that folder. But I don't understand why I would not have permission to access the folder in question here, especially when it works fine in Excel 2019.
I know that it is possible for Excel VBA to write a file to this particular folder on Mac, because I have a workbook (not created by me) that does it. Unfortunately, the code on that workbook is password-protected, so I can't see how they do it.
Anyone have any ideas what might be wrong?