Need help to stop another excel file getting opened

Get help with using AutoHotkey and its commands and hotkeys
kwfine
Posts: 16
Joined: 26 Nov 2015, 06:46

Need help to stop another excel file getting opened

23 Aug 2018, 05:54

Hi all,

I have this AHK script running in my Windows 7. It opens a test1.xls file when I press the F2 key.
The script is fine but there is a little problem:
After a test1.xls has been opened, if I press the F2 key again, there will be another test1.xls opened.
That means if I press the F2 key 4 times, there will be 4 test1.xls opened.

I am looking for a solution for the problem.
Can you help me please?

Code: Select all

F2::
path := "C:\test1.xls"   
sleep, 100
XL := ComObjCreate("Excel.Application")
sleep, 100
XL.Workbooks.Open(path)
return
User avatar
TheDewd
Posts: 1390
Joined: 19 Dec 2013, 11:16
Location: USA

Re: Need help to stop another excel file getting opened

23 Aug 2018, 08:09

Code: Select all

#SingleInstance, Force

F2::
	Path := "C:\test1.xls"

	Try {
		XL := ComObjActive("Excel.Application")
	} Catch {
		XL := ComObjCreate("Excel.Application")
	}

	For Workbook in XL.Workbooks {
		If (Workbook.FullName = Path) {
			return
		}
	}

	XL.Workbooks.Open(Path)
return
Image Bulldozer - Sokoban inspired game from 1994 recreated in AutoHotkey.

Return to “Ask For Help”

Who is online

Users browsing this forum: GTM, Rohwedder, timoshina and 356 guests