How to get filepath of current file (Excel)

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
ADR_
Posts: 4
Joined: 02 Feb 2016, 09:57

How to get filepath of current file (Excel)

02 Mar 2018, 03:59

Hi,

I've created some hotkeys for Excel. That works fine. How can I get the filepath of the current Excel file?

Regards,

Anika
Odlanir
Posts: 659
Joined: 20 Oct 2016, 08:20

Re: How to get filepath of current file (Excel)

02 Mar 2018, 05:03

Code: Select all

Xl := ComObjActive("Excel.Application")
MsgBox % Xl.ActiveWorkbook.Path
____________________________________________________________________________
Windows 10 Pro 64 bit - Autohotkey v1.1.30.01 64-bit Unicode
Johana
Posts: 189
Joined: 02 May 2017, 02:34

Re: How to get filepath of current file (Excel)

02 Mar 2018, 05:04

ADR_ wrote:Hi,

I've created some hotkeys for Excel. That works fine. How can I get the filepath of the current Excel file?

Regards,

Anika

Hello! I am not a coder but I think you can do it like this:

Code: Select all

xl := ComObjActive("Excel.Application")
MsgBox, %xl.ActiveWorkbook.Path%
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: How to get filepath of current file (Excel)

02 Mar 2018, 05:50

This should do it.

Code: Select all

;[Excel_Get function]
;MS-Office-COM-Basics/Excel_Get.ahk at master · ahkon/MS-Office-COM-Basics · GitHub
;https://github.com/ahkon/MS-Office-COM-Basics/blob/master/Examples/Excel/Excel_Get.ahk

q:: ;excel - get path
oXl := Excel_Get()
vPath := oXl.ActiveWorkbook.FullName ;dir+name
vDir := oXl.ActiveWorkbook.Path ;dir
vName := oXl.ActiveWorkbook.Name ;name
MsgBox, % vPath "`r`n" vDir "`r`n" vName
oXl := ""
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
ADR_
Posts: 4
Joined: 02 Feb 2016, 09:57

Re: How to get filepath of current file (Excel)

02 Mar 2018, 07:09

Thank you for your prompt reactions. However, I haven't got the faintest idea how to test the options (I've tried all of them). Can you tell me step by step where to put the code? Sofar all my attempts have failed.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: filipemb, mapcarter, peter_ahk, Rohwedder and 309 guests