7

When in Windows 10 or in Windows 7, if I have an Excel file open and I want to know the path to the file I can use the ‘open current file in explorer’ button and it opens that file in the Windows Explorer, where I can copy the path to the file.

However, in Mac, I am not able to find any option like that unless I open Finder and find the current file's name, then right click and choose Get Info on the file there.

I do not want to do a lot of work just to get the file path. Is there an easy way to do this?

  • 3
    You get the folder hierarchy by ctrl-clickin' or right-clickin` on the file name at the top of the document window (at least in Office 2011) – klanomath Nov 22 '17 at 20:24
5

The Excel function

=CELL("filename",A1)

will give you the complete path to a file that has been saved. You can copy the result of the function and use Paste Values to retain only the text.

If the file has not yet been saved, the function returns a blank.

1

You can 'option-right click' the file from finder and one option is to copy the file path to clipboard. This at least gives you access to the path.

0

This task is super simple with AppleScript in Excel from Office 2011.

(I can't presently confirm it works with Office 2016.)

----------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2017/11/28 15:34
# dMod: 2017/11/28 15:39
# Appl: Microsoft Excel
# Task: Get the front document's container folder path & its full path.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Microsoft_Excel, @Front, @Document, @Container, @Folder, @Path, @Full, @Path
# Test: Tested only in Excel 14.7.1 (of Office 2011) on macOS 10.12.6
----------------------------------------------------------------

tell application "Microsoft Excel"
   tell front document
      set docContainerPathHFS to path
      set docFullPath to full name
   end tell
end tell

set the clipboard to docFullPath

----------------------------------------------------------------


You can get the path to the document's container folder or its full path.

Here's another technique using UI-Scripting that works with most applications even if they're NOT scriptable. (I've added error-handling to this one.)

----------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2017/11/28 15:25
# dMod: 2017/11/28 15:30 
# Appl: Microsoft Excel, System Events
# Task: Copy path of frontmost Excel document to the Clipboard.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @ASObjC, @Microsoft_Excel, @System_Events, @Copy, @Path, @Frontmost, @Excel, @Document, @Clipboard
# Test: Tested only in Excel 14.7.1 (of Office 2011) on macOS 10.12.6
----------------------------------------------------------------

use AppleScript version "2.4" -- Yosemite and later
use framework "Foundation"
use scripting additions

try

   tell application "System Events"
      tell application process "Microsoft Excel"
         tell (first window whose subrole is "AXStandardWindow")
            set fileURL to value of attribute "AXDocument"
         end tell
      end tell
   end tell

   set posixPathOfFrontExcelDocument to (current application's class "NSURL"'s URLWithString:fileURL)'s |path|() as text
   set the clipboard to posixPathOfFrontExcelDocument

on error e number n
   set e to e & return & return & "Num: " & n
   if n ≠ -128 then
      try
         tell application (path to frontmost application as text) to set ddButton to button returned of ¬
            (display dialog e with title "ERROR!" buttons {"Copy Error Message", "Cancel", "OK"} ¬
               default button "OK" giving up after 30)
         if ddButton = "Copy Error Message" then set the clipboard to e
      end try
   end if
end try

----------------------------------------------------------------

Excel (2011) has its own script menu, so using AppleScripts with it is quite easy.

I'm told the Office 2016 products no longer have script menus.

Personally I use both FastScripts and Keyboard Maestro to overcome such limitations. I confine most of my AppleScripts to FastScripts and use Keyboard Maestro for many other automation tasks.

-ccs

0

You can control-click (right-click) the icon/filename at the top of the excel window, and the path will be displayed. Moving the cursor to any folder, or even the file itself, will open a finder window with (whatever you selected) displayed.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .