excel open specific sheet Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Lapas
Posts: 8
Joined: 12 Jun 2017, 16:51

excel open specific sheet

17 Oct 2017, 07:14

im using:

Code: Select all

Pathy= %A_WorkingDir%\new.xlsx
X1X := ComObjCreate("Excel.Application")									X1X.Workbooks.Open(Pathy) 
X1X.Visible := true
-at excel new.xlsx i have many sheets i need to know how can i open specific sheet for example open me second sheets, his name is JFK.

-and second question if is possible open excel new.xlsx and make new sheets with command
User avatar
TheDewd
Posts: 1510
Joined: 19 Dec 2013, 11:16
Location: USA

Re: excel open specific sheet  Topic is solved

17 Oct 2017, 08:17

Example:

Code: Select all

#SingleInstance, Force

ObjExcel := ComObjCreate("Excel.Application")
ObjExcel.Visible := True
ObjWorkbook := ObjExcel.Workbooks.Add()
return

F1::
    ObjWorkbook.Worksheets.Add() ; Add Worksheet
return

F2::
    ObjWorkbook.Worksheets(1).Select ; Select Worksheet
return

F3::
    ObjWorkbook.Worksheets("Sheet3").Select ; Select Worksheet by Name
return
User avatar
king-of-hearts
Posts: 30
Joined: 01 Oct 2017, 06:29

Re: excel open specific sheet

17 Oct 2017, 11:38

You can try this:

Code: Select all

pathy := A_WorkingDir . "\new.xlsx"
xls := ComObjCreate("Excel.Application")
xls.visible := true
xls.workbooks.open(pathy)
xls.sheets("JFK").select ; selects the sheet
return
https://autohotkey.com/boards/viewtopic.php?f=6&t=38707 - MS Access Manager - SQL Query: Incredible tool for MS Access/SQL Queries on the fly!!
User avatar
FanaticGuru
Posts: 1906
Joined: 30 Sep 2013, 22:25

Re: excel open specific sheet

17 Oct 2017, 13:20

king-of-hearts wrote:

Code: Select all

pathy := A_WorkingDir . "\new.xlsx"
xls := ComObjCreate("Excel.Application")
xls.visible := true
xls.workbooks.open(pathy)
xls.sheets("JFK").select ; selects the sheet
return
I use Activate instead of Select but I don't know if there is a great deal of difference.

Code: Select all

xlApp := ComObjActive("Excel.Application")
xlApp.Sheets(2).Activate	; Can use index or specific name
FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
Lapas
Posts: 8
Joined: 12 Jun 2017, 16:51

Re: excel open specific sheet

20 Oct 2017, 13:36

thanks guys.. i need solve one last problem:
i need add and rename so i tipe:

Code: Select all

oExcel.Worksheets.Add() ; Add Worksheet
oExcel.Sheets("sheet1").Name := "Summary"
this work!! but i need oExcel.Sheets("sheet1").Name := "Summary" selecet variable sheets soo i try:

Code: Select all

var="sheet1"
oExcel.Worksheets.Add() ; Add Worksheet
oExcel.Sheets(var).Name := "Summary"
;didnt work

Code: Select all

var="sheet1"
oExcel.Worksheets.Add() ; Add Worksheet
oExcel.Sheets(%var%).Name := "Summary"
;this code too didnt work 
i need solve rename how i can choose the name from variable, thanks you anyway
User avatar
king-of-hearts
Posts: 30
Joined: 01 Oct 2017, 06:29

Re: excel open specific sheet

20 Oct 2017, 13:47

Code: Select all

xls := ComObjCreate("Excel.Application")
xls.visible := true
xls.workbooks.add()
var := "Summary" 
xls.sheets(1).name := var
xls.sheets(var).select ; selects the sheet
https://autohotkey.com/boards/viewtopic.php?f=6&t=38707 - MS Access Manager - SQL Query: Incredible tool for MS Access/SQL Queries on the fly!!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Anput, Google [Bot], Nerafius, RandomBoy and 113 guests