logo
search
VBA & Macro Problems

How to Save an Excel Text Box as a Picture Using a VBA Macro

Camila MilosovichCamila Milosovich Oct 16, 2026 869 views

Question details

The user needs to export a specific text box or shape from an Excel worksheet into an image file using a VBA macro without losing text formatting.

How to Save an Excel Text Box as a Picture Using a VBA Macro
Product
Excel
Device & OS
not provided
Scenario
Automating the extraction and saving of spreadsheet elements, such as formatted text boxes, directly to the desktop or a folder as an image file (e.g., JPG).
Observed behavior
Excel does not offer a direct one-line VBA equivalent for the right-click 'Save as Picture' menu, requiring a script to copy the shape to the clipboard, paste it as an image, and then export it.
Before you start

Ensure your workbook is saved as a Macro-Enabled Workbook (.xlsm) and that the Developer tab is enabled. Verify the exact name of your text box in the Selection Pane before running the code.

Solution 1Recommended

Use the CopyPicture Method to Export the Shape

This method copies the text box exactly as it appears on your screen, pastes it temporarily as an image object, exports it to your desktop, and cleans up the temporary file.

Using the CopyPicture method instead of a standard Copy command is the most reliable way to preserve your font characteristics, alignment, and formatting.

The macro utilizes Windows Script Host to dynamically locate your Desktop folder, ensuring the code works seamlessly without needing to hardcode a user profile path.

1
Open the VBA Editor

Press Alt + F11 on your keyboard to open the Visual Basic for Applications window, then click Insert > Module from the top menu to create a blank script.

2
Paste the Macro Code

Copy and paste the provided subroutine starting with 'Sub Shape_As_Picture_Desktop()'. Make sure to change 'Sheet1' and 'TextBox 1' to the actual names used in your workbook.

3
Run the Macro

Click anywhere inside the macro code block and press F5, or click the Run button (green triangle) in the toolbar. The text box will instantly be processed and saved as a .jpg file on your desktop.

Use the CopyPicture Method to Export the Shape
Image Format and Quality: JPEG export may not preserve fine font details perfectly. For higher quality results, change the FilterName parameter to 'PNG' and the file extension to '.png' in the VBA code.
Seamless VBA Compatibility

Automate Shape Exports with WPS Spreadsheet

WPS Office offers robust macro support, allowing you to run standard VBA scripts seamlessly. You can easily insert text boxes, style them, and use VBA macros to export them as pictures exactly as you would in Excel.

  1. 1. Open your Document: Launch WPS Spreadsheet and open the document containing your text box.
  2. 2. Access the Visual Basic Editor: Navigate to the Developer tab in the top ribbon and click on 'Visual Basic Editor' to launch the scripting environment.
  3. 3. Insert the Export Script: Right-click your project, choose Insert > Module, and paste the CopyPicture macro code provided in the solution.
  4. 4. Execute the Macro: Run the code to instantly export your selected text box as an image file directly to your desired local directory.
Fully compatible with Microsoft Excel formats, including Macro-Enabled Workbooks (.xlsm).Supports executing advanced VBA macros for efficient workflow automation.Free, lightweight, and features an intuitive tabbed user interface.Powerful tools for inserting, formatting, and manipulating shapes and text boxes.
microsoft office alternative - wps office

Frequently Asked Questions

How do I find the exact name of my text box to use in the macro?

Click on the text box in your worksheet. The name of the shape will appear in the Name Box located directly to the left of the formula bar (e.g., 'TextBox 1'). You can type a new name here to rename it if desired.

Can I save multiple text boxes as pictures at once using VBA?

Yes, you can hold the Ctrl key, select multiple text boxes, right-click, and choose 'Group'. Then, simply reference the new grouped shape's name in your VBA script to export them together as a single picture.

Why is the exported picture from the macro slightly blurry?

The standard VBA JPEG export applies compression to the image. To achieve a sharper export, modify the VBA code parameter to export the file as a PNG instead of a JPG, or switch the Appearance setting from xlScreen to xlPrinter.