-
Notifications
You must be signed in to change notification settings - Fork 71
/
Open_or_add_a_workbook.ahk
68 lines (57 loc) · 3.39 KB
/
Open_or_add_a_workbook.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
; Usage:
; F11 hotkey - Open a workbook in the active instance of Excel.
; F12 hotkey - Open a workbook in a new instance of Excel.
; Win+F11 hotkey - Create a new blank workbook in the active instance of Excel.
; Win+F12 hotkey - Create a new blank workbook in a new instance of Excel.
; Ctrl+F11 hotkey - Create a new workbook in the active instance of Excel using 'FilePath' as the workbook template.
; Ctrl+F12 hotkey - Create a new workbook in a new instance of Excel using 'FilePath' as the workbook template.
; The workbook to use for this example.
FilePath := A_ScriptDir "\Test.xlsx"
return ; End of Auto-execute section.
; Excel hotkeys
#IfWinActive, ahk_class XLMAIN
; F11 hotkey - Open a workbook in the active instance of Excel.
F11::
xlApp := Excel_Get() ; Excel_Get - https://autohotkey.com/boards/viewtopic.php?f=6&t=31840
xlApp.Workbooks.Open( FilePath ) ; Open the workbook specified by 'FilePath'.
xlApp := "" ; Done using this COM object so clear the variable.
return
; F12 hotkey - Open a workbook in a new instance of Excel.
F12::
xlApp := ComObjCreate("Excel.Application") ; Create an instance of Excel.
xlApp.Visible := true ; Make Excel visible.
xlApp.Workbooks.Open( FilePath ) ; Open the workbook specified by 'FilePath'.
xlApp := "" ; Done using this COM object so clear the variable.
return
; Win+F11 hotkey - Create a new blank workbook in the active instance of Excel.
#F11::
xlApp := Excel_Get() ; Excel_Get - https://autohotkey.com/boards/viewtopic.php?f=6&t=31840
xlApp.Workbooks.Add() ; Create a new blank workbook.
xlApp := "" ; Done using this COM object so clear the variable.
return
; Win+F12 hotkey - Create a new blank workbook in a new instance of Excel.
#F12::
xlApp := ComObjCreate("Excel.Application") ; Create an instance of Excel.
xlApp.Visible := true ; Make Excel visible.
xlApp.Workbooks.Add() ; Create a new blank workbook.
xlApp := "" ; Done using this COM object so clear the variable.
return
; Ctrl+F11 hotkey - Create a new workbook in the active instance of Excel using 'FilePath' as the workbook template.
^F11::
xlApp := Excel_Get() ; Excel_Get - https://autohotkey.com/boards/viewtopic.php?f=6&t=31840
xlApp.Workbooks.Add( FilePath ) ; Create a new workbook using 'FilePath' as the template.
xlApp := "" ; Done using this COM object so clear the variable.
return
; Ctrl+F12 hotkey - Create a new workbook in a new instance of Excel using 'FilePath' as the workbook template.
^F12::
xlApp := ComObjCreate("Excel.Application") ; Create an instance of Excel.
xlApp.Visible := true ; Make Excel visible.
xlApp.Workbooks.Add( FilePath ) ; Create a new workbook using 'FilePath' as the template.
xlApp := "" ; Done using this COM object so clear the variable.
return
; Turn off context-sensitive hotkeys.
#If
; Press {Escape} to exit this script.
Esc::ExitApp
; Excel_Get - https://autohotkey.com/boards/viewtopic.php?f=6&t=31840
; <Paste the Excel_Get function definition here>