VBScript: How do I apply TableStyle "Green, TableStyle Medium 14" to entire table

GJDouglas

New Member
Joined
Jun 22, 2023
Messages
6
Office Version
  1. 365
Platform
  1. Windows
Via VBScript: I am reading a CSV file, applying various formats to columns, then writing it as an XLSX. I need to appy the "Green, TableStyle Medium 14" to it, but haven't been able to figure it out. I could only find one suggestion from google searching, but I cannot get it to work.

Ex.
1687463179459.png


Script setup:
Set fso = CreateObject("Scripting.FileSystemObject")
file = PathAndFileName.CSV
With CreateObject("Excel.Application")
Set WB = .Workbooks.Open(file)

Failed VBScript code:
WB.ActiveSheet.ListObjects.Add(xlSrcRange, Range(TableRange), , xlYes).Name = "myTable"
WB.ActiveSheet.ListObjects("myTable").TableStyle = "TableStyleMedium14"

Could someone please guide me to a solution?
Thanks....
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
I apolgize... I realized that I forgot to include how I derived "TableRange" used above. Following is that code:
LastRow = WB.Sheets(1).UsedRange.Rows.Count
LastCell = "F" & LastRow
RowString = "A1:"
TableRange = RowString & LastCell
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top