Go to a specific sheet on excel Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Empaque
Posts: 8
Joined: 16 May 2022, 23:28

Go to a specific sheet on excel

06 Sep 2022, 12:49

Im writing a code that needs to change constantly from vairious excel sheets, i found this code to activate an specified sheet in the active book of excel.

Code: Select all

F1::
Xl := ComObjActive("Excel.Application") ;creates a handle to your currently active excel sheet
Xl.Sheets("Sheet1").Activate
return
My question is, how can i use a variable to change each sheet.

My idea was this code:

Code: Select all

F2::
count=1
Xl := ComObjActive("Excel.Application") ;creates a handle to your currently active excel sheet
Xl.ActiveSheet.Range("b1").select
send ^c
#HotkeyModifierTimeout, 100
sleep 500
StringReplace, clipboard, clipboard, `r`n,, all

Tipo=%Clipboard%
WinActivate, PORMEM_ADE1
Xl := ComObjActive("Excel.Application") ;creates a handle to your currently active excel sheet
Xl.Sheets("%Tipo%").Activate
return
I got an error in the last line before return, i guess its only the way i want to introduce the variable bue i dont find thw way to do it correctly, i´ll be so gretfull if some one can help me.
Heezea
Posts: 59
Joined: 30 Sep 2013, 21:33

Re: Go to a specific sheet on excel  Topic is solved

06 Sep 2022, 13:14

Try Xl.Sheets(Tipo).Activate

Recall that when a parameter is in brackets, you're sending the value of the parameter so you don't need the " or the %. Xl.Sheets("Tipo").Activate would activate a sheet named Tipo.

Similarly but opposite, when not in brackets, you do need the %

Code: Select all

MsgBox, % Tipo " is the value of Tipo.`nWhen the % is in the front, it's similar to a parameter of a function."
MsgBox, Tipo is the name of the variable, not the contents.
MsgBox, %Tipo% is the value of Tipo.
It's probably worth reading the documentation on variable expression.
Empaque
Posts: 8
Joined: 16 May 2022, 23:28

Re: Go to a specific sheet on excel

06 Sep 2022, 13:22

Thnaks a lot, that now works.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot] and 180 guests