Excel (VBA) in AHK Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Yoshimu
Posts: 38
Joined: 14 Nov 2014, 09:02

Excel (VBA) in AHK

17 May 2017, 03:09

Hey,
at this moment I use:

Code: Select all

XL.Range("G200").Select
XL.ActiveCell.Offset(0,0).Value := Var1
But this cell "A200" every day changes.
So I Would like to use FInd function, that will look for defined text eg "Client name" in Column G (or other). Than if VBA found, select this cell.
Is it possible to implement something like this in AHK?

Thanks for any help :)
User avatar
jmeneses
Posts: 524
Joined: 28 Oct 2014, 11:09
Location: Catalan Republic

Re: Excel (VBA) in AHK

17 May 2017, 03:47

Code: Select all

q::
WinActivate ahk_exe EXCEL.EXE
oExcel := ComObjActive("Excel.Application")
If (IsObject(oExcel))
    For oCell in oExcel.Range["ClientName"]   
    If (oCell.Value){
        Msgbox % "Find at "   RegExReplace(oCell.address,"\$")  " VALUE (" oCell.Value ")"
    }

oExcel:="" 
Return
Attachments
XLS ClientName.png
XLS ClientName.png (9.78 KiB) Viewed 1357 times
Donec Perficiam
User avatar
FanaticGuru
Posts: 1908
Joined: 30 Sep 2013, 22:25

Re: Excel (VBA) in AHK  Topic is solved

17 May 2017, 10:54

Yoshimu wrote:Hey,
at this moment I use:

Code: Select all

XL.Range("G200").Select
XL.ActiveCell.Offset(0,0).Value := Var1
But this cell "A200" every day changes.
So I Would like to use FInd function, that will look for defined text eg "Client name" in Column G (or other). Than if VBA found, select this cell.
Is it possible to implement something like this in AHK?

Thanks for any help :)
Not entirely sure exactly what you want so here is general knowledge about Find.

Here is example code of Finding a value in a column.

Code: Select all

Xl := ComObjActive("Excel.Application")

InputBox, Needle, Search, % "Workbook:`t" Xl.ActiveWorkbook.Name "`nSheet: `t`t" Xl.ActiveSheet.Name "`n`n" "Enter Search String for Column G"

Found := Xl.Columns("G").Find(Needle)
if !Found
{
	MsgBox NOT FOUND
	ExitApp
}
MsgBox % Found.Address "`t=`t" Found.Value
This allows you to enter what to look for in column G.

If you want to Find the value in cell A200 in the column G, you can do:

Code: Select all

Needle := Xl.Range("A200").Value
Found := Xl.Columns("G").Find(Needle)
The Find command allows a bunch of options. https://msdn.microsoft.com/en-us/librar ... 39746.aspx

Find is also much quicker and more efficient than looping through all the cells in a range.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
Yoshimu
Posts: 38
Joined: 14 Nov 2014, 09:02

Re: Excel (VBA) in AHK

17 May 2017, 11:13

Great FG.
I was trying Find function before i started this topic, but thanks to ur example I udderstood how it works ( and why it didnt work before)

I simply needed this:

Code: Select all

XL.Columns("G").Find("John").Select

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot] and 119 guests