Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Excel - Convert used range to table?
#2
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
Code:
Copy      Help
;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


Messages In This Thread
Excel - Convert used range to table? - by pgomez - 02-26-2019, 08:11 PM
RE: Excel - Convert used range to table? - by pgomez - 02-27-2019, 07:17 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)