When I run the script below, I get an error on line 3.
Error: OpenText method of Workbooks class failed.
I have tried everything I could think of, including changing the
delimiter to a comma, but have had no success opening an excel
workbook.
=====================================================================
1. Set XL = CreateObject("Excel.Application")
2. XL.Visible=True
3. XL.Workbooks.OpenText "C:\AAASASPivot\RawData.txt", 437, 1, 1,
-4142, False, False, False, False, False, True, "|"
4. XL.Sheets.Add.name = "TestPivotTable3"
5. XL.ActiveSheet.PivotTableWizard SourceType=xlbase,
xl.sheets("RawData").UsedRange, "TestPivotTable3!R1C1", "pvttbl"
6. XL.ActiveSheet.PivotTables("pvttbl").PivotFields("Sex").Orientation
= 1
7. XL.ActiveSheet.PivotTables("pvttbl").PivotFields("Age").Orientation
= 1
8. XL.ActiveSheet.PivotTables("pvttbl").PivotFields("Age").numberformat
= "00"
9. XL.ActiveSheet.PivotTables("pvttbl").AddDataField
XL.ActiveSheet.PivotTables("pvttbl").PivotFields("Height"), "Sum of
Height", -4157
10. XL.ActiveSheet.PivotTables("pvttbl").PivotFields("Sum of
Height").numberformat = "#,##0.00"
11. XL.ActiveSheet.Columns.AutoFit
.....
=====================================================================
These lines of code (with minor modification) are taken from a paper by
Ted Conway on "Creating Microsoft Excel PivotTables in a Jiffy from
SAS(R) Data". I am trying to re-create his method, but without
success.
Thanks to one and all for any help.
Thanks