Error 31032 in VBA—often labeled "31132" in some sources—occurs when your code fails to create an embedded object (like a chart, form control, or ActiveX component). This happens most commonly when trying to add Excel charts, Word forms, or external ActiveX controls. The root cause is usually misconfiguration, missing dependencies, or incorrect object reference syntax. The quick solution is to manually embed the object in Excel, then reference it via VBA, or use the correct object name for your environment.

What You'll Need

  • A Microsoft Office application with VBA enabled (Excel, PowerPoint, Word)
  • The specific object type you wish to embed (e.g., Excel chart, ActiveX control)
  • Access to the object’s host application (e.g., Excel for charts, Access for forms)
  • Admin rights to install/uninstall software if needed (for ActiveX issues)

Step-by-Step Resolution

  1. Check Object Type and Host Application
    1. Determine the exact object type you’re trying to embed. Was it a chart? A form control? An ActiveX control? Each requires a different approach.
    2. Verify you’re embedding from the correct host. For example:
      • Excel charts must be created within Excel and referenced via Excel’s `ChartObject` class.
      • Word forms require embedding from Word itself, and VBA must use `Forms` namespace.
      • ActiveX controls (e.g., data grids) must be installed on the machine and referenced via `OLEObject` or `ActiveXControl` class.
  2. Manually Embed the Object
    1. Open the host application (e.g., Excel, Word) and manually create the object:
      • For charts: Go to Insert > Charts, then right-click the chart > Chart Object > Link to Excel Data (if dynamic).
      • For forms: Insert > Quick Parts > ActiveX Control > Browse to select the form (e.g., `MSForms` in Word).
      • For ActiveX controls: Use Control Panel > Add/Remove Programs > Check "Install ActiveX controls" in Office settings (if applicable).
    2. Once embedded, close the host application (do not save changes unless required).
  3. Reference the Object in VBA Properly
    1. Open the VBA editor (Alt+F11). In the Project Explorer, expand the workbook/module containing your code.
    2. Add the correct namespace or object reference:
      • For Excel charts: Dim shpChart As ChartObject Then reference via `ThisWorkbook.Sheets("Sheet1").ChartObjects.Add(...)`.
      • For Word forms: Dim frm As Form Use `ThisDocument.FormControls.Add(msForms.Form, ...)`.
      • For ActiveX controls: Dim oCtrl As OLEObject Use `With oCtrl.Accepts` (or similar, depending on control type).
    3. Declare the object’s class in the module: Private Sub UserForm_Initialize() For Word forms, ensure you’ve included the `Forms` namespace by adding Option Explicit and checking the References tab (Microsoft Forms 2.0 Object Library).
  4. Verify ActiveX Permissions
    1. If embedding an ActiveX control, ensure:
      • Office is installed with ActiveX support (common in Pro/Enterprise versions).
      • The control is registered on the machine (run `regsvr32` for the DLL, if needed).
      • The VBA user has admin rights to install drivers (some controls require this).
    2. Test in a fresh workbook (not an existing one with embedded objects) to rule out corruption.

If That Did Not Work

If steps 1–4 fail, proceed with these advanced troubleshooting steps:
  1. Reset VBA Settings
    1. Close all Office applications.
    2. Run the following command in Command Prompt (Admin) to reset Office settings: c:\windows\system32\rundll32.exe setupapi.dll, StartProcessWithDesiredCredentials (Replace with the correct path if needed.)
    3. Restart your PC and reattempt embedding.
  2. Reinstall Office Components
    1. Uninstall Office via Control Panel > Programs > Microsoft Office.
    2. Reinstall only the components you need (Excel/PowerPoint/Word) from the Microsoft Store or official installer.
    3. Ensure you select "ActiveX support" during installation if embedding ActiveX controls.
  3. Check for Compatibility Issues
    1. Ensure your VBA code targets the correct version of Excel/Word.
      • For Office 365: Use `Object` or `Scripting.Dictionary` for modern APIs.
      • For older versions: Use `Chart` object syntax (e.g., `ChartObjects.Add` with older parameters).
    2. Test in a new install of Office to isolate conflicts.

Common Mistakes

  1. Forgetting to Close the Host Application Embedding an object from Excel while Word is open (or vice versa) causes the VBA runtime to fail. Always close the host before referencing it via VBA.
  2. Incorrect Object Namespace Using `Chart` when you meant `ChartObject` (or `Form` vs. `Forms` namespace) leads to errors. Check the object’s class library in the VBA editor.
  3. ActiveX Controls Without Installation Many ActiveX controls (e.g., data grids) require the DLL to be registered. Run `regsvr32` in Admin mode after installation.
  4. Outdated Office Version Older versions (e.g., Office 2010) may lack support for new object types. Update to the latest version if possible.

Tips

  1. Use the "Create Object" Dialog In VBA, insert a reference to the object’s library (e.g., `Microsoft Excel 16.0 Object Library`) via Tools > References. This often resolves missing type definitions.
  2. Test in a Blank Workbook Recreate the issue in a new, empty workbook to rule out corruption in existing files.
  3. Check for 32-bit/64-bit Conflicts If embedding ActiveX on a 64-bit system, ensure you’re using 64-bit VBA (select Microsoft Excel XX.0 Object Library with the correct bitness).
  4. Enable Debugging Add Debug.Print Err.Description to your code to see the exact error message when the runtime fails.

Troubleshooting

  1. Error Persists After Steps 1–5 The issue may be environment-specific (e.g., corporate firewall blocking ActiveX). Test on a different machine or with a clean user profile.
  2. VBA Editor Crashes When Adding References Try:
    • Running Excel in Safe Mode (Start > Run > `excel /safe`).
    • Deleting the VBA project file (`_vbaProject.fap`) and rebuilding it.
  3. Embedding a Chart But VBA Still Fails Some chart types (e.g., embedded as a linked object) require additional VBA: With ActiveSheet.ChartObjects.Add(Left:=100, Width:=200) .Chart.Type = xlLine // Specify chart type here End With

Frequently Asked Questions

Why does my VBA code fail to create an embedded object in Excel?

The most common cause is trying to embed a chart or control while Excel is closed. Always close the host application (Excel) before referencing objects via VBA.

How do I embed a Word form in Excel using VBA?

You cannot directly embed a Word form in Excel. Instead, create the form in Word, then load it into Excel using `Forms` namespace in VBA. Example: Dim frm As Form: Set frm = ThisWorkbook.FormControls.Add(msForms.Form, "Sheet1!A1", 100, 100)

What if I get error 31032 when embedding an ActiveX control?

This often means the control’s DLL is missing or not registered. Install the control, then run regsvr32 [control.dll] in Admin Command Prompt.

Can I embed a PowerPoint object in Excel via VBA?

PowerPoint objects are not natively embeddable in Excel. You’d instead use PowerPoint’s API (complex) or export content to Excel’s native formats.

Why does my VBA code work in one workbook but not another?

Corruption, different Office versions, or missing references in the second workbook cause this. Test in a brand-new workbook before diagnosing.

How do I fix VBA error 31032 if I’m using PowerPoint?

PowerPoint does not support embedded VBA objects. Use PowerPoint’s API or export data to Excel instead.