02-27-2019, 07:17 PM
(This post was last modified: 02-27-2019, 07:19 PM by pgomez.
Edit Reason: Clarified the error & added signature
)
Oh - I figured it out!
I made two mistakes.
1. The xRg variable needs to be an Excel.Range object. (Should have read the MSDN documentation for Excel ListObjects.Add more closely.)
2. The first parameter should be Excel.xlSrcRange, not Excel.xlSourceRange. (I'm surprised that both are valid, but only one can be used in this case. I read right over that when I read the MSDN documentation.)
So, this code works:
Macro Excel Testing
Thank you anyway! Please keep up the great work.
-Phil
I made two mistakes.
1. The xRg variable needs to be an Excel.Range object. (Should have read the MSDN documentation for Excel ListObjects.Add more closely.)
2. The first parameter should be Excel.xlSrcRange, not Excel.xlSourceRange. (I'm surprised that both are valid, but only one can be used in this case. I read right over that when I read the MSDN documentation.)
So, this code works:
Macro Excel Testing
;Prep sample Excel File
ExcelSheet es.Init("" 4|16)
es.SetCell("Header_1" "A1")
es.SetCell("Header_2" "B1")
es.SetCell("Item_1" "A2")
es.SetCell("Item_2" "B2")
;Convert used range to table
Excel.Range xRg=es.ws.UsedRange
VARIANT tStyle="TableStyleLight1"
es.ws.ListObjects.Add(Excel.xlSrcRange xRg @ Excel.xlYes @ tStyle).Name="MyTable"
Thank you anyway! Please keep up the great work.
-Phil