02-26-2019, 08:11 PM
Hello,
I would like to create a macro that uses COM for MS Excel to convert a used range to a table. Basically, I'd like to do what I can easily do through the Excel gui (Insert > Table) without going through the user interface.
Here's my first attempt:
Macro Excel Testing
I feel like I'm on the right track, but whenever I run the program, QM gives this error message on the last line: 0x80020009, Exception occurred
Advice?
-Phil
P.S. - I am a long-time user (since around 2003) and first-time poster. I just have to say that QM is one of the most valuable tools I have ever purchased. It literally changed the course of my career for the better. I can't thank you, Gintaras, enough.
I would like to create a macro that uses COM for MS Excel to convert a used range to a table. Basically, I'd like to do what I can easily do through the Excel gui (Insert > Table) without going through the user interface.
Here's my first attempt:
Macro Excel Testing
;typelib Excel {00020813-0000-0000-C000-000000000046} 1.9
ExcelSheet es.Init("" 1|4|16)
es.SetCell("Header_1" "A1")
es.SetCell("Header_2" "B1")
es.SetCell("Item_1" "A2")
es.SetCell("Item_2" "B2")
int c r cc rc
es.GetRangeInfo("<used>" c r cc rc)
VARIANT xRg=ExcelRange(c r cc rc)
VARIANT tStyle="TableStyleLight1"
VARIANT tName="Table1"
es.ws.ListObjects.Add(Excel.xlSourceRange xRg @ Excel.xlYes @ tStyle).Name=tName
I feel like I'm on the right track, but whenever I run the program, QM gives this error message on the last line: 0x80020009, Exception occurred
Advice?
-Phil
P.S. - I am a long-time user (since around 2003) and first-time poster. I just have to say that QM is one of the most valuable tools I have ever purchased. It literally changed the course of my career for the better. I can't thank you, Gintaras, enough.