How to Export Only Selected Excel Worksheets as Separate PDFs in WPS Office
Question details
The user wants a VBA macro in WPS Office Spreadsheets that exports only the currently selected Excel worksheets to separate PDF files, rather than exporting every worksheet in the workbook.

- Product
- WPS Office Spreadsheets
- Device & OS
- not provided
- Scenario
- The user has an Excel workbook with multiple worksheets and needs to distribute selected sheets as individual PDF files, possibly to different locations.
- Observed behavior
- The existing macro loops through every worksheet in the workbook and exports all sheets; the expected behavior is to export only the worksheets selected before running the macro.
Open the workbook in WPS Office Spreadsheets and make sure the Developer tab is available so you can open the VBA editor. If macros are disabled, enable them for this file, and select the worksheet tabs you want to export before you run the macro.
Replace the Worksheet Loop with ActiveWindow.SelectedSheets in the VBA Macro
Use this method when you need the macro to respect the worksheet tabs currently selected in WPS Office Spreadsheets and export each selected sheet as its own PDF.
The existing export macro likely loops through ThisWorkbook.Worksheets, which always processes the entire workbook. Changing the loop to ActiveWindow.SelectedSheets makes the export target only the sheets you selected before running the macro.
In WPS Office Spreadsheets, hold Ctrl and click each worksheet tab to select individual sheets, or hold Shift and click the first and last tab to select a range.
Go to the Developer tab and click Visual Basic, or press Alt+F11, to open the WPS Office VBA editor.
In the macro code, find the loop that iterates through worksheets and replace the collection with ActiveWindow.SelectedSheets, for example: For Each w In ActiveWindow.SelectedSheets.
Inside the loop, retain or add w.ExportAsFixedFormat Type:=0 or a Save As PDF command so each selected worksheet is exported as its own PDF.
Return to the workbook, confirm the required tabs are still selected, then run the macro from Developer > Macros and choose the macro name.

Use Separate Macros for Different Output Folders
Choose this approach when selected sheets must be saved to different locations or named for different couriers or departments.
Export Selected Worksheets as Individual PDFs with WPS Office VBA
WPS Office Spreadsheets supports VBA macros, so you can replace the worksheet loop with ActiveWindow.SelectedSheets and export only the selected worksheets as separate PDF files. The workflow remains familiar and keeps your workbook and PDF export compatible with Microsoft Excel formats.
- 1. Open your workbook in WPS Office Spreadsheets: Launch WPS Office, open the workbook, and make sure the Developer tab is visible.
- 2. Select the worksheet tabs: Hold Ctrl or Shift and click the tabs you want to turn into PDFs.
- 3. Open the VBA editor and update the loop: Click Developer > Visual Basic or press Alt+F11, then change the loop to use ActiveWindow.SelectedSheets.
- 4. Run the macro: Return to the workbook and run the macro from Developer > Macros to export each selected sheet as a separate PDF.

Frequently Asked Questions
How do I select only certain worksheets before running the PDF export macro?
In WPS Office Spreadsheets, hold Ctrl and click worksheet tabs for individual sheets, or hold Shift and click the first and last tab for a contiguous range. The ActiveWindow.SelectedSheets loop then exports only those selected tabs.
Why does my VBA macro still export all worksheets after adding ActiveWindow.SelectedSheets?
Check that you replaced the loop collection and not just a variable name. The loop must be For Each w In ActiveWindow.SelectedSheets, not For Each w In ThisWorkbook.Worksheets, and the workbook window must be active.
Can each selected worksheet be saved as a separate PDF with the worksheet name?
Yes. Use w.Name in the PDF output file path so each PDF receives the corresponding worksheet name instead of a shared or fixed file name.
Can I send each exported PDF to a different folder from the same macro?
You can, but it is clearer to create separate macros for each destination or add sheet-name-based path logic. In WPS Office Spreadsheets, open Developer > Visual Basic, add a module, and define the output folder for each worksheet by name.
Does exporting selected sheets as PDF work with WPS Office if the workbook was created in Microsoft Excel?
Yes. WPS Office Spreadsheets can open .xlsx and .xlsm files and run compatible VBA macros. The PDF export can be applied to selected sheets in the same workbook.




