This is a sample of combine specific worksheets in multiple workbooks. https://club.excelhome.net/forum.php?mod=viewthread&tid=1659202&page=1&mobile=
Specify a worksheet to combine - Office Scripts
The two sample codes below are retrived from Combine worksheets into a single workbook - Office Scripts documentation https://learn.microsoft.com/en-us/office/dev/scripts/resources/samples/combine-worksheets-into-single-workbook For a workbook that contains multiple worksheets, is it possible to combine a specific worksheet that has the same name or the first/last sheet in the workbook? For example, I have two Excel files called A and B. A has two sheets, called sheet 1 and sheet 2, while B has one sheet called sheet 1. After running the example flow, A.sheet1, A.sheet2 and B.sheet1 are all added to the combined Excel file. My motivation is to get rid of A.sheet2.
Office Development
4 answers
Sort by: Most helpful
-
-
peiye zhu 165 Reputation points
2023-04-21T10:27:31.6+00:00 network block repeat post
-
Deleted
This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.
Comments have been turned off. Learn more
-
Yutao Huang - MSFT 701 Reputation points Microsoft Employee
2023-04-21T16:56:57.6933333+00:00 You can probably tweak the first script in the sample code to only export the worksheets you are interested in.
For example:
/** * This script returns the values from the used ranges on each worksheet. */ function main(workbook: ExcelScript.Workbook): WorksheetData[] { // Create an object to return the data from each worksheet. let worksheetInformation: WorksheetData[] = []; // Add the names of the worksheets to be exported. Here only "Sheet1" is included. Add more names to the list if needed. const sheetNamesToBeIncluded = ["Sheet1"]; // Get the data from every worksheet, one at a time. workbook.getWorksheets().forEach((sheet) => { const sheetName = sheet.getName(); // Only export worksheets we want if (sheetNamesToBeIncluded.includes(sheetName)) { let values = sheet.getUsedRange()?.getValues(); worksheetInformation.push({ name: sheetName, data: values as string[][] }); } }); return worksheetInformation; } // An interface to pass the worksheet name and cell values through a flow. interface WorksheetData { name: string; data: string[][]; }