https://support.microsoft.com/en-us/kb/257757 said "Microsoft strongly recommends a number of alternatives that do not require Office to be installed server-side, and that can perform most
common tasks more efficiently and more quickly than Automation.
Most server-side Automation tasks involve document creation or editing. Office 2007 supports new Open XML file formats that let developers create, edit, read, and transform file content on the server side. These file formats use the System.IO.Package.IO namespace
in the Microsoft .NET 3.x Framework to edit Office files without using the Office client applications themselves. This is the recommended and supported method for handling changes to Office files from a service."
Currently, I have a program that uses an existing XLS that already format the column headers with colors and has formulas for some cells, runs a Macro in an XLS file that queries a TXT file, creates a Pivot table, and save the XLS sheet to a different
XLS file.
Below is an example of the XLS column header. There are formulas behind the $0 (for ex: =SUMIF(B6:B31378,"=Open",K6:K31378)
The codes for the Macro is the below.
How can I do this without using Office client application ?
Thank you.
Sub myMacro(Var1, Var2) With ActiveSheet.QueryTables.Add(Connection:= _"TEXT;" & Var1, Destination:=Range("A6")) .Name = "oc_1" .FieldNames = True .RowNumbers = False .FillAdjacentFormulas = False .PreserveFormatting = True .RefreshOnFileOpen = False .RefreshStyle = xlInsertDeleteCells .SavePassword = False .SaveData = True .AdjustColumnWidth = True .RefreshPeriod = 0 .TextFilePromptOnRefresh = False .TextFilePlatform = 437 .TextFileStartRow = 1 .TextFileParseType = xlDelimited .TextFileTextQualifier = xlTextQualifierDoubleQuote .TextFileConsecutiveDelimiter = False .TextFileTabDelimiter = False .TextFileSemicolonDelimiter = False .TextFileCommaDelimiter = False .TextFileSpaceDelimiter = False .TextFileOtherDelimiter = "|" .TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, _ 1, 1, 1, 1) .TextFileTrailingMinusNumbers = True .Refresh BackgroundQuery:=False End With Rows("6:6").Select Range(Selection, Selection.End(xlDown)).Select ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _"OC_Report!R5C1:R25000C23").CreatePivotTable TableDestination:="", _ TableName:="PivotTable1", DefaultVersion:=xlPivotTableVersion10 ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1) ActiveSheet.Cells(3, 1).Select ActiveSheet.PivotTables("PivotTable1").RowGrand = False ActiveSheet.PivotTables("PivotTable1").AddFields RowFields:=Array("Firm", _"open/" & Chr(10) & "closed") ActiveSheet.PivotTables("PivotTable1").PivotFields("open/" & Chr(10) & "closed").Orientation _ = xlDataField Worksheets("OC_Report").Activate ActiveSheet.Range("A6").Select Worksheets("Sheet1").Activate Sheets("Sheet1").Select Sheets("Sheet1").Name = "OCF" Worksheets("OC_Report").Activate ActiveSheet.Range("A6").Select Dim active As Workbook Set active = Application.ThisWorkbook Dim wb As Workbook Set wb = Workbooks.Add active.Activate Sheets("OC_Report").Select Sheets("OC_Report").Copy Before:=Workbooks(wb.Name).Sheets(1) active.Activate Sheets("OCF").Select Sheets("OCF").Copy After:=Workbooks(wb.Name).Sheets(1) active.Activate Sheets("MyTab2").Select Sheets("MyTab2").Copy After:=Workbooks(wb.Name).Sheets(1) wb.Sheets("Sheet1").Delete ActiveWorkbook.SaveAs Filename:= _ Var2, FileFormat:=xlNormal, _ Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _ CreateBackup:=False End Sub