FWIW, I created a spreadsheet that matches the guidelines in @flyingDman's V2 example: name - vlookuptest.xlsx, 2 columns, 23 rows, cells in column A were junk text except for one entry "matrix" and just sequential integers in column B. I also changed the path in his code to point to my file.
As long as all the criteria were as listed above, it worked perfectly. If I changed the range, or changed "matrix" to something else, or pointed to a nonexistent file - basically anything that would case the lookup to fail, I got the same error code, albeit with different text description.
Make sure everything matches correctly. You may want to try his second alternative as well - less prone to throwing Excel errors.
Russ
Thank you for the tips, @RussF. I made a sheet from scratch and the code provided by @flyingDman worked.
Google error 0x800A03EC and see what could be the issue. There are a number of potential problems but they are likely related to Excel and Windows rather than AHK. Have you been able to run other scripts with COM for Excel?
To access a different sheet use this:CODE:
xl.worksheets("sheet2").range("a1:b23")
Also watch this: https://www.youtube.com/watch?v=ZI5FLSll9AY
Thanks @RussF for testing!
@flyingDman, thank you for the very informative video. I was actually aware that there are better alternatives to VLookup, like Index Match and XLookup, but I figured I would get more responses if asked about VLookup.
The code below works on a brand new spreadsheet:
CODE:
#Requires Autohotkey v2.0+
#SingleInstance force
needle := "matrix"
xl := ComObject("Excel.Application")
Workbook := xl.Workbooks.Open("C:\Users\username\AutoHotkey\Excel\vlookuptest.xlsx")
xl.worksheets("test").range("a:b")
range_lookup := 0; := false is OK
msgbox xl.WorksheetFunction.VLookup(needle, xl.range("a:b"), 2, range_lookup)
Workbook.close(0)
xl.quit
However, I realized that this won't work for me because I need an easy way to input the lookup value (column A) and have the output value (column B) show up on a MsgBox or be pasted on the text. I tried adding a hotkey to trigger an InputBox to store the input as a variable, but this is a little too advanced for me and v2 syntax is killing me. How can I dynamically replace the value of needle with user input?
Statistics: Posted by Avastgard — Today, 12:42