Hello,
I would like, using COM, to add a worksheet after the last worksheet.
In the VBA documentation i read that the VB command is:
ActiveWorkbook.Sheets.Add(After:=ActiveWorkbook.Worksheets(ActiveWorkbook.Worksheets.Count))
This command "as is" doesn't work in autohotkey.
How could I convert this command to the authotkey COM form?
I leave here the page of the VBA documentation
Thank you
https://learn.microsoft.com/en-us/office/vba/api/excel.sheets.add
Excel COM add sheet after the last sheet Topic is solved
Re: Excel COM add sheet after the last sheet Topic is solved
Code: Select all
F12::ExcelAddSheetLast()
ExcelAddSheetLast() {
xlSheets := ComObjActive("Excel.Application").ActiveWorkbook.Sheets
xlSheets.Add(, xlSheets.Item(xlSheets.Count))
}
Re: Excel COM add sheet after the last sheet
Dear datapoint,Datapoint wrote: ↑11 Feb 2024, 19:20Code: Select all
F12::ExcelAddSheetLast() ExcelAddSheetLast() { xlSheets := ComObjActive("Excel.Application").ActiveWorkbook.Sheets xlSheets.Add(, xlSheets.Item(xlSheets.Count)) }
your code is working like a charm and I thank you for the help.
It happends quite often to me that I find the solution in VBA code and then I don't know to how to convert it in "COM/AHK" code.
Does exist some tutorial to operate this conversion?
Thank you so much!
Gabriele
Re: Excel COM add sheet after the last sheet
Glad to hear it's working for you.
For tutorials on converting VBA to AHK there is this one: viewtopic.php?f=7&t=8978
There are lots of examples on the forum that can be found with google or the like. Usually you can find something similar to what you are trying to do if you search the AHK site for a specific Excel task. For example, add a worksheet using AHK searching: site:autohotkey.com excel add worksheet
For tutorials on converting VBA to AHK there is this one: viewtopic.php?f=7&t=8978
Re: Excel COM add sheet after the last sheet
thank you, man!
Very useful resources!
Very useful resources!