Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi everyone, I was currently working on a project which required all charts and tables to be extracted to a single excel file with charts on first page and tables on the next. Before I start for the bigger fish I tried with a trial version of a simpler script. The script is as follows:- Function ExportCharts() Set xlApp = CreateObject("Excel.Application") xlApp.Visible = true Set xlDoc = xlApp.Workbooks.Add 'open new workbook nSheetsCount = 0 CALL RemoveDefaultSheet(xlDoc) nSheetsCount = xlDoc.Sheets.Count xlDoc.Sheets(nSheetsCount).Select Set xlSheet = xlDoc.Sheets(nSheetsCount) CALL ExportRevenueWidgets(xlDoc,xlSheet) End Function 'Call Export Widgets By Sheet Function ExportRevenueWidgets(xlDoc,xlSheet) CALL Export(xlDoc,xlSheet,"CH03", "A") CALL Export(xlDoc,xlSheet,"CH07", "D") CALL Export(xlDoc,xlSheet,"CHO8", "B") CALL Export(xlDoc,xlSheet,"CH09", "C") CALL Export(xlDoc,xlSheet,"CH13", "E") CALL Export(xlDoc,xlSheet,"CH07", "F") End Function 'Export Widgets Function Export(xlDoc, xlSheet,widgetID, columnStart) nRow = xlSheet.UsedRange.Rows.Count nRow = 1 Set SheetObj = ActiveDocument.GetSheetObject(widgetID) 'Copy the chart object to clipboard SheetObj.CopyTableToClipboard true 'Paste the chart object in Excel file xlSheet.Paste xlSheet.Range(columnStart&nRow) End Function 'Remove Default Sheets from Excel Files Sub RemoveDefaultSheet(xlDoc) Do nSheetsCount = xlDoc.Sheets.Count If nSheetsCount = 1 then Exit Do Else xlDoc.Sheets(nSheetsCount).Select xlDoc.ActiveSheet.Delete End If Loop End Sub If someone could point my mistake it would be fantastic. Thanks in advance.
Have a look here: Loop Charts and Field Values - Excel Export Macro and here: VB Macro to Loop Field (Dynamic) and Export Chart (Dynamic) to Excel & Name Sheets by Field Valu....
- Marcus