Page 1 of 1

This is the gui phrase I used in v1, but I want to change it to the v2 version.

Posted: 09 May 2024, 03:13
by note_korean

Code: Select all

buttonfindexcel:
{
	Gui, Submit, nohide
	FileSelectFile, filename,3,%A_ScriptDir% , Open a input Excel file, Excel files(*.xlsx)
	if filename =
		MsgBox, You didn't select a file
	else
		GuiControl, ,a5, %filename%
	return
}
buttonexcelsetting:
{
	coordmode, mouse,screen
	coordmode, pixel,screen
	Gui, Submit, nohide
	aexcel1:= ComObjCreate("Excel.Application")
	where = %a5%
	sleep 50
	aexcel1.Workbooks.open(where)
	sleep 50
	aexcel1.visible:=true
	sleep 50
	return
}
I'm a very newbie.

Re: This is the gui phrase I used in v1, but I want to change it to the v2 version.

Posted: 09 May 2024, 04:59
by boiler
You need to show the code where the GUI is created, which apparently you’ve already translated to v2 since you didn’t include that. We don’t even know the name of the GUI object.

Re: This is the gui phrase I used in v1, but I want to change it to the v2 version.

Posted: 13 May 2024, 00:20
by note_korean
I'll think about it a little more and post the exact question.
Thank you for your answer.

Re: This is the gui phrase I used in v1, but I want to change it to the v2 version.

Posted: 13 May 2024, 01:02
by Seven0528
 @note_korean
Next time, please provide executable code in your questions.
Answering questions with incomplete code snippets requires a lot of inference, which may not be appropriate. Thank you.
다음부터는 실행 가능한 코드로 질문 글을 작성해 주세요.
코드가 불완전하면 여러모로 유추해야 할 것이 많아 답변드리기에 적절치 않습니다. 감사합니다.

Code: Select all

#Requires AutoHotkey v2.0
#SingleInstance Force
myGui := gui()
editPath := myGui.add("Edit", "w400 ReadOnly")
btnFindExcel := myGui.add("Button", "w400", "Find Excel")
btnFindExcel.onEvent("Click", btnFindExcel_Click)
btnExcelSetting := myGui.add("Button", "w400", "Excel Setting")
btnExcelSetting.onEvent("Click", btnExcelSetting_Click)
myGui.show()

btnFindExcel_Click(guiCtrlObj, info)    {
    global editPath
    filename := fileSelect(1|2, A_ScriptDir, "Open a input Excel file, Excel files(*.xlsx)")
    if (filename = "")
        msgBox "You didn't select a file"
    else
        editPath.Text := filename
}

btnExcelSetting_Click(guiCtrlObj, info)    {
    where := editPath.Text
    if (where = "")
        return
    aexcel1 := comObject("Excel.Application")
    sleep 50
    aexcel1.Workbooks.open(where)
    sleep 50
    aexcel1.Visible := true
    sleep 50
}

Code: Select all

#Requires AutoHotkey v1.1
#SingleInstance Force
gui Add, Edit, w400 ReadOnly veditPath
gui Add, Button, w400 ggButtonFindExcel, Find Excel
gui Add, Button, w400 ggButtonExcelSetting, Excel Setting
gui Show
return

gButtonFindExcel:
    fileSelectFile filename, % 1|2, %A_ScriptDir% , Open a input Excel file, Excel files(*.xlsx)
    if (filename = "")
        msgBox You didn't select a file
    else
        guiControl,, editPath, %filename%
    return

gButtonExcelSetting:
    gui Submit, Nohide
    where := editPath
    if (where = "")
        return
    aexcel1 := comObjCreate("Excel.Application")
    sleep 50
    aexcel1.Workbooks.open(where)
    sleep 50
    aexcel1.Visible := true
    sleep 50
    return

Re: This is the gui phrase I used in v1, but I want to change it to the v2 version.

Posted: 13 May 2024, 01:14
by Seven0528
 Gui creation code can be written succinctly as follows.

Code: Select all

btnFindExcel := myGui.add("Button", "w400", "Find Excel")
btnFindExcel.onEvent("Click", btnFindExcel_Click)
btnExcelsetting := myGui.add("Button", "w400", "Excel Setting")
btnExcelsetting.onEvent("Click", btnExcelSetting_Click)

Code: Select all

myGui.add("Button", "w400", "Find Excel").onEvent("Click", btnFindExcel_Click)
myGui.add("Button", "w400", "Excel Setting").onEvent("Click", btnExcelSetting_Click)