My Ahk Excel Script


Guide and explanation to my most useful script:

Once I created this script to help me use Excel, I absolutely cannot live without it.
The ease and convenience being able to bring these shortcuts with me anywhere I go is short of amazing. Just take the Ahk portable file on a USB flash drive and load it on any PC.
Here I will decode my script and clarify what the function of each hotkey that I have set up.
I have written the same inside the script as well and will be demonstrating each of the functions.
Download my script here.

Firstly you need to get your Ahk master script to automatically launch my Excel script.
Click here to learn how.

Open up the script and let's go to town. Warning, its a long journey. 
(Don't worry though, this may all seem daunting at first, but once you invest some time into learning this. I promise you it will help save you so much time not having to do the little things anymore.)

_____________________________________________________________________________

1. Only one instance of this script will run to prevent multiples of the same script to run.
#SingleInstance Ignore ; Makes sures that only one instance of this script runs

_____________________________________________________________________________

2. This prevents your hotkeys from activating when Excel is not your active window.
#IfWinActive ahk_class XLMAIN ; Make sure to have this top line for this script to run when ONLY ;Excel window is active

Example: ` + 5 hotkey to work in Excel not in Notepad or anything else for that matter

SC029 & 5::           ; ` + 5
Send, Only4Excel ;Only4Excel
return
; End of Code

_____________________________________________________________________________

3. The function key, the most important key.
This key is the pre-requisite for almost all the hotkeys I have programmed.
It works by pressing ` then another key to initiate a hotkey. I use ` due to it not being tied to any default windows shortcut nor is it used often at all. Which makes it perfect in this circumstance.
This was done with the sample 'How to insert a single row'.
Below I explain how I fixed ` as once you set it up as a function key it no longer works.

; This is to fix my ` button
; I use the ` key as my 'Function key', meaning most of my hotkeys are binded to ` and is almost ;always the beginning key.
; The reason why you need to add these lines of code is because whenever a key is used as the ;initiator for a hotkey,
; that key then itself ceases to work as it will be waiting for the next key to execute the hotkey.
; Therefore this code essentially remaps the ` to send itself, effectively making the ` work again.
$SC029::Send {vkC0sc029} 
return
; End of Code

; This is to fix my ~ button Left Shift
; Because the ` does not work as explained above, consequently the ~ does not work.
; So these lines are to fix that problem, as they will allow you to enter ~ using either the left or right  ; shift key once again.
LShift & SC029::
Send, ~
return
; End of Code

; This is to fix my ~ button Right Shift
RShift & SC029::
Send, ~
return
; End of Code

_____________________________________________________________________________ 
4. Special Pastes

Excel has the ability to paste accordingly to specific conditions. I have made these hotkeys for the ones I use the most, however you are free to add more as you please.

; This is to initiate 'Paste Special - Format' command in Excel
SC029 & t::               ;~ + t
Send, ^!vt {Enter}     ;ctrl + alt + v + t + enter
return
; End of Code

; This is to initiate 'Paste Special - Values' command in Excel
SC029 & v::            ;~ + v
Send, ^!vv {Enter}   ;ctrl + alt + v + v + enter
return
; End of Code

; This is to initiate 'Paste Special - Multiply' command in Excel
RAlt & m::               ;Right alt + m
Send, ^!vm {Enter} ;ctrl + alt + v + m + enter
return
; End of Code

To create your 'Paste Special' simply copy a cell and press ' Ctrl + Alt + v ' to open up the Paste Special menu. From there you can choose which function you want, in this example we'll choose transpose. Notice how in the menu you see 'Tranpose' this means the activating key is 'e', so change the 2nd line in the code to and replace the final 'v' with 'e', as the 'v' is used to command the 'Values' Paste Special. All in all, this shortens the 5 keys it would normally take to execute 'Paste Special - Transpose' into only 2 keys.

; This is to initiate 'Paste Special - Transpose' command in Excel
SC029 & e::           ;~ + e , 1st line is your activation keys.
Send, ^!ve {Enter}  ;ctrl + alt + v + e + enter, 2nd line is what the script sends to the PC after you ;activate the hot key.
return
; End of Code

_____________________________________________________________________________ 
5. Autofitting all the cells so you don't need to double click each column.

Self explanatory, this autofits the content within a cell so that all of it is visible.
SC029 & f::         ;Right ~ + f
Send, !hoi           ;alt + h + o + i
return
; End of Code

_____________________________________________________________________________ 
6. Remember the 
'How to insert a single row' example? 
This here is for both inserting a row or column.

; This is to initiate 'Insert Row' command in Excel
SC029 & r:: ; User input - Press ` + r keys
Send, !hir ; Your PC then sends alt + h + i + r ,
; which is the sequence of keys required to make MS Excel insert a single row.
; Note, ! means 'alt' in Ahk scripts
return ; You must put return at the bottom as it signifies the End of the Script

;'Insert Column' command in Excel 
SC029 & c::
Send, !hic ; Your PC then sends alt + h + i + c ,
; which is the sequence of keys required to make MS Excel insert a single row.
; Note, ! means 'alt' in Ahk scripts
return ; You must put return at the bottom as it signifies the End of the Script

_____________________________________________________________________________

We finally made it to the bottom. 
But this isn't the deepest. 
I've got more content coming soon.
Click here to head back.


© 2020 Brian Pho. All rights reserved.
Powered by Webnode
Create your website for free! This website was made with Webnode. Create your own for free today! Get started