Excel same file different sheet Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Fulminare
Posts: 369
Joined: 26 Jun 2021, 20:15

Excel same file different sheet

22 Sep 2021, 04:58

There are 2 scripts almost identical and 1 excel filewith 2 sheets.

script A should enter data into the sheet called "one"
script B should enter data into the sheet called "two"

Script A

Code: Select all

xl := ComObjCreate("excel.application")
wrkbk := xl.workbooks.open("C:\Users\user\Desktop\New Microsoft Excel Worksheet (2).xlsx")

lstrw := xl.Range("B" xl.Rows.Count).End(-4162).Row
mnth := strsplit(xl.Range("C" lstrw).value, "-").2


nwrw := lstrw + 1
nmbr := xl.Range("B" lstrw).value


if nmbr is not number
	nmbr := 0
if (mnth != A_MMM) {
	nmbr := 0
	nwrw++
}



;ENTRIES 

xl.Range("A" nwrw).value := nick
xl.Range("B" nwrw).value := runs
xl.Range("B" nwrw).NumberFormat := "## "
xl.Range("C" nwrw).value := A_DD "-" A_MM "-" A_YYYY
xl.Range("D" nwrw).NumberFormat := "[$-en-US]h:mm Am/Pm;@"
xl.range("D" nwrw).value := A_Hour ":" A_Min ":" A_Sec

wrkbk.close(1)
xl.quit()


Script B

Code: Select all

xl := ComObjCreate("excel.application")

wrkbk := xl.workbooks.open("C:\Users\user\Desktop\New Microsoft Excel Worksheet (2).xlsx")
;wrkbk := xl.workbooks.open("C:\Users\user\Desktop\New Microsoft Excel Worksheet.xlsx")

wrkbk1.activate
wrkbk1.Sheets("Fees").Select

lstrw := xl.Range("B" xl.Rows.Count).End(-4162).Row
mnth := strsplit(xl.Range("C" lstrw).value, "-").2


nwrw := lstrw + 1
nmbr := xl.Range("B" lstrw).value


if nmbr is not number
	nmbr := 0
if (mnth != A_MMM) {
	nmbr := 0
	nwrw++
}



;ENTRIES 
FormatTime, lastMonth, %	A_Now - 100000000, MMM

colbtxt :=static text
xl.Range("A" nwrw).value := nick
xl.Range("B" nwrw).value := colbtxt
;xl.Range("B" nwrw).NumberFormat := "## "
xl.Range("C" nwrw).value := A_DD "-" A_MM "-" A_YYYY


wrkbk.close(1)
xl.quit()
I tried using this In both scripts ( this is an example from the internet. I changed Sheet2 to it's actual name)

Code: Select all

wrkbk1.activate
wrkbk1.Sheets("Sheet2").Select
but that is entering both the scripts' data into sheet "two"

Can someone please tell me what to do ?

Regards
User avatar
TheDewd
Posts: 1510
Joined: 19 Dec 2013, 11:16
Location: USA

Re: Excel same file different sheet  Topic is solved

22 Sep 2021, 10:22

Instead of using wrkbk1.activate, try XL.Sheets("Your Sheet Name").Activate for each script.
Fulminare
Posts: 369
Joined: 26 Jun 2021, 20:15

Re: Excel same file different sheet

22 Sep 2021, 10:48

It is working.

Thank you !

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: fiendhunter and 232 guests