kalekje / LNCHR-pub

MIT License
24 stars 4 forks source link

Does Search/REPLACEME support multiline code? #15

Open Avastgard opened 7 months ago

Avastgard commented 7 months ago

I am trying to run a script with the REPLACEME feature inside of it (type s - search). The script basically performs a VLookup in an Excel spreadsheet, saves the value in the clipboard and pastes it.

    needle := REPLACEME.value
    xl := ComObject("Excel.Application")
    Workbook := xl.Workbooks.Open("C:\Users\username\AutoHotkey\Excel\spreadsheet.xlsx")
    xl.worksheets("Sheet1").range("a:b")
    range_lookup := 0
    A_Clipboard := Xl.WorksheetFunction.VLookup(needle, xl.range("a:b"), 2, range_lookup)
    Workbook.close(0)
    xl.quit
    Send "^v"
    return

The problem is I keep running into the following error message:

image

Looking at the specified code lines in LNCHR-Commands.ahk, it shows like this:

if ((input == "vlookup") and (UsingAnyWorkcomputer)) ; vlookup 
{
lngui_enable_query("", make_run_ReplaceTexts_func("needle := REPLACEME.value
    xl := ComObject("Excel.Application")
    Workbook := xl.Workbooks.Open("C:\Users\username\AutoHotkey\Excel\spreadsheet.xlsx")
    xl.worksheets("teste").range("a:b")
    range_lookup := 0
    A_Clipboard := Xl.WorksheetFunction.VLookup(needle, xl.range("a:b"), 2, range_lookup)
    Send "^v"
    Workbook.close(0)
    xl.quit
    return"))
return
}

Any idea how I can fix it?

kalekje commented 7 months ago

Short answer is no, but you could easily deconstruct the code that the "s"-type makes and use it in a blank-type cell (arbitrary code). But I don't think that's what you want here. The "s"-type cells are meant for simple one-liners with replacing text (think URLs or single commands for the command line).

What you should do is put all that code into a function that takes one arg and use a "n"-type cell with lngui_enable_query("TitleToAppear", YourFunc). YourFunc would use REPLACEME as an argument. You can put your custom functions in their own file or add on to LNCHR-Funcs.ahk

lngui_enable_query changes the GUI mode so that the next thing you type into the texbox is the input to YourFunc. A unique title should be used, and this title is shown on the GUI window as well as it being used to store memory.