VBA - Getting Computer Name and User Name on a Mac, Excel 2011

willardpeabody

New Member
Joined
Aug 2, 2011
Messages
1
Hi!

I'm finding it difficult to do one specific thing. I want to open a workbook that has the same filename on 2+ different computers, all of these computers being Macs (OSX version 10.5 and later).

The problem is when I use the following code to open a specific workbook, it will only open on the computer with that Computer name ('Macintosh HD') and that user name ('MainUser'):
Workbooks.Open Filename:= _
"Macintosh HD:Users:MainUser:Documents:Folder1:Example.xlsm"

How do I get it to open a file with the same name and in the same folder, except on a different computer with a different user? (So that this file can be shared and my macros can run effectively on each computer.)

Is there some way to use a name for a computer/user that is generic and not specific to one computer and user? Can I open the workbook in another way without referencing the entirety of the file's path?

I own a copy of Mr. Excel's textbook 'VBA and Macros: Microsoft Excel 2010,' but I could not find an answer there!! Other solutions that I found online either involve Windows API, which the Mr. Excel textbook says only works on windows. Likewise, using some sort of Environ("username") function also does not work on a Mac, I'm told. I'm sure that there is someway this can work on a Mac!

I hope someone can help me with this simple problem! There's not a lot of support out there for Excel 2011 for Mac! (Especially because it's so new.)

Thanks so much,

Will
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
To get the current file path use CurDir in VBA, then parse the result by searching for the colon (:) character to capture the portion of the file path up to the 3rd colon.
 
Upvote 0
Hi Will,
Did you ever solve this problem, I have a similar one?
Jon


Hi!

I'm finding it difficult to do one specific thing. I want to open a workbook that has the same filename on 2+ different computers, all of these computers being Macs (OSX version 10.5 and later).

The problem is when I use the following code to open a specific workbook, it will only open on the computer with that Computer name ('Macintosh HD') and that user name ('MainUser'):
Workbooks.Open Filename:= _
"Macintosh HD:Users:MainUser:Documents:Folder1:Example.xlsm"

How do I get it to open a file with the same name and in the same folder, except on a different computer with a different user? (So that this file can be shared and my macros can run effectively on each computer.)

Is there some way to use a name for a computer/user that is generic and not specific to one computer and user? Can I open the workbook in another way without referencing the entirety of the file's path?

I own a copy of Mr. Excel's textbook 'VBA and Macros: Microsoft Excel 2010,' but I could not find an answer there!! Other solutions that I found online either involve Windows API, which the Mr. Excel textbook says only works on windows. Likewise, using some sort of Environ("username") function also does not work on a Mac, I'm told. I'm sure that there is someway this can work on a Mac!

I hope someone can help me with this simple problem! There's not a lot of support out there for Excel 2011 for Mac! (Especially because it's so new.)

Thanks so much,

Will
 
Upvote 0

Forum statistics

Threads
1,223,909
Messages
6,175,313
Members
452,634
Latest member
cpostell

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