You can add a logo to an Excel workbook with VBA in two main ways: insert a picture file into a worksheet, or place a logo image in the header/footer so it prints on every page. The worksheet method is the most reliable and gives you control over position and size. The header/footer method is better for printed reports but has stricter size and format limits. This guide covers both, with the exact VBA you need and the pitfalls to avoid.

What You'll Need

  • Excel for Windows or Mac (the VBA editor is built in; no add-in required).
  • A logo image file saved locally, ideally in PNG, JPG, or BMP format. For header/footer logos, use a small image (roughly 100–200 pixels wide) because Excel scales it to fit the header area.
  • Macro-enabled workbook (.xlsm) if you want the code to persist.
  • Basic familiarity with the VBA editor (Alt+F11 on Windows, Fn+Option+F11 on Mac).

Step-by-Step

  1. Open the VBA editor. Press Alt+F11 (Windows) or Fn+Option+F11 (Mac). If the Project Explorer is not visible, press Ctrl+R (Windows) or Cmd+R (Mac).
  2. Insert a module. In the Project Explorer, right-click your workbook name, choose Insert > Module. This is where you will paste the code.
  3. Paste the worksheet logo macro. Use this code, replacing the file path with the actual location of your logo:
    Sub InsertLogoOnSheet()
        Dim ws As Worksheet
        Dim logoPath As String
        Set ws = ActiveSheet
        logoPath = "C:\Images\logo.png"  ' change to your file path
        On Error Resume Next
        ws.Shapes("CompanyLogo").Delete
        On Error GoTo 0
        ws.Shapes.AddPicture Filename:=logoPath, LinkToFile:=msoFalse, _
            SaveWithDocument:=msoTrue, Left:=10, Top:=10, Width:=120, Height:=40
        ws.Shapes(ws.Shapes.Count).Name = "CompanyLogo"
    End Sub
    The macro deletes any existing shape named "CompanyLogo" to avoid duplicates, then inserts the picture at the top-left corner (10 points from left and top) with a fixed size. Adjust Left, Top, Width, and Height as needed. The shape is named so you can reposition or delete it later.
  4. Run the macro. Press F5 while the cursor is inside the Sub, or go back to Excel and use Developer > Macros (enable the Developer tab via File > Options > Customize Ribbon if needed). Select InsertLogoOnSheet and click Run.
  5. Check the result. The logo should appear on the active sheet. If it does not, verify the file path and that the image file exists. The On Error Resume Next line suppresses errors, so remove it temporarily to see the actual error message.
  6. For a header/footer logo (print-only), use this alternative. Excel's PageSetup object supports a picture in the left, center, or right header/footer. Paste this code:
    Sub InsertLogoInHeader()
        Dim ws As Worksheet
        Set ws = ActiveSheet
        ws.PageSetup.LeftHeaderPicture.Filename = "C:\Images\logo.png"
        ws.PageSetup.LeftHeader = "&G"
    End Sub
    The &G code tells Excel to display the graphic. The image will appear in the left header of every printed page. Note that header/footer images are limited to certain formats (BMP, JPG, PNG, GIF) and are scaled to fit; very large images may look blurry.
  7. Save the workbook as .xlsm. If you have not already, use File > Save As and choose Excel Macro-Enabled Workbook. Otherwise the macro will be lost when you close the file.
  8. Test printing (for header method). Use File > Print or Ctrl+P to preview. The logo should appear in the header area. If it does not, check that the header text contains &G and that the picture path is correct.

Common Mistakes

  • Hardcoding a file path that only exists on your computer. If you share the workbook, the macro will fail on other machines. Use a relative path or store the image in the workbook (SaveWithDocument:=msoTrue) so it travels with the file.
  • Forgetting to delete old logos. Running the macro multiple times without the delete step creates stacked images. The code above handles this by naming the shape.
  • Using an unsupported image format. Header/footer pictures must be BMP, JPG, PNG, or GIF. Other formats may cause errors.
  • Not enabling macros. If macros are disabled, the code will not run. Check the Trust Center settings (File > Options > Trust Center > Trust Center Settings > Macro Settings).
  • Assuming the logo will appear on all sheets. The worksheet macro only affects the active sheet. Loop through Worksheets to apply it everywhere.

Tips

  • Use a PNG with a transparent background for a cleaner look on colored cells.
  • Anchor the logo to a cell range if you want it to move with data: set the shape's TopLeftCell property after insertion.
  • For a logo that appears on every sheet, modify the macro to loop: For Each ws In ThisWorkbook.Worksheets ... Next ws.
  • Keep the logo small (under 200 KB) to avoid bloating the workbook size.
  • If you need the logo in the header on multiple sheets, set PageSetup for each sheet individually; there is no global header setting.

Troubleshooting

If the macro runs but no logo appears, first check the file path. A common issue is using a path with spaces without quotes, but the AddPicture method handles spaces fine. More likely, the image is inserted off-screen or behind other objects. Use the Selection Pane (Home > Find & Select > Selection Pane) to see all shapes and bring the logo to front. If you get a "File not found" error, verify the path and that the file extension matches the actual format. For header logos, if the image does not print, ensure the header margin is large enough to accommodate the image; adjust via Page Layout > Margins > Custom Margins. Also confirm that &G is in the correct header section (LeftHeader, CenterHeader, or RightHeader). If the logo appears distorted, set both Width and Height proportionally or omit one to let Excel scale. On Mac, file paths use colons instead of backslashes in VBA; use Macintosh HD:Users:YourName:logo.png style paths or use the Application.PathSeparator property.

Frequently Asked Questions

Can I add a logo to multiple sheets at once?

Yes. Modify the macro to loop through ThisWorkbook.Worksheets and call the insertion code for each sheet. Be aware that each sheet will have its own copy of the image, increasing file size.

Will the logo appear when I print?

Worksheet logos print if they are within the print area. Header/footer logos always print on every page of the specified sheet. Use the header method for consistent placement across pages.

Why does my header logo look blurry?

Excel scales header images to fit the header area, which can cause blurriness. Use a higher-resolution image (at least 300 DPI at the intended print size) and keep the aspect ratio close to the header dimensions.

Can I use a logo from a URL?

No, the AddPicture method requires a local file path. Download the image first, then reference the local file.

Does this work in Excel for Mac?

Yes, but file paths use colons (:) instead of backslashes (\). Also, some PageSetup properties behave differently on Mac; test the header method before relying on it.

How do I remove the logo later?

For worksheet logos, delete the shape named "CompanyLogo" using ActiveSheet.Shapes("CompanyLogo").Delete. For header logos, clear the header text and remove the picture via PageSetup.LeftHeaderPicture.Filename = "".