Share via

Automating Alt Text Application for Images in Word

Julian, Melissa 0 Reputation points
2025-11-20T16:06:24.3766667+00:00

I am currently working on projects in Microsoft Word that involve inserting a large number of PNG images, created in Illustrator, into multiple Word documents. Our goal is to automate the process of applying alt text to these images within the word documents.

Is there a specific plugin or add-in available for Microsoft Word that could streamline the process of mapping and applying alt text from external data sources to images?

Microsoft 365 and Office | Word | For business | Windows
0 comments No comments

4 answers

Sort by: Most helpful
  1. Vy Nguyen 10,130 Reputation points Microsoft External Staff Moderator
    2025-11-23T19:25:47.7033333+00:00

    Hi @Julian Melissa

    Thank you for providing the updated details. We appreciate the extra context you’ve shared regarding your workflow. 

    Based on your description, you are encountering difficulties running your script that reads PNG file names from Excel column A and uses the descriptions in column B to populate Alt Text in a Word document, with an additional error about not finding the spreadsheet despite the correct path and naming.  

    Below are some workarounds that suit your situation: 

    I created a sample Word document with two sample PNG pictures (warning.png and house/png), which were downloaded from the internet. User's image

    For the subscription in the Excel sheet, I use the same two columns as you're doing in your file: file name in column A and alt_text in column B. 

    User's image

    Now in the Word document, press Alt + F11 to open the VBA editor or open it via the Developer tab > Visual Basic. Then press Insert > Module and paste this VBA script into it: 

    Sub ApplyAltTextFromExcel()  
        Dim xlApp As Object  
        Dim xlWB As Object  
        Dim xlSheet As Object  
        Dim dict As Object  
        Dim lastRow As Long  
        Dim i As Long  
          
        Set dict = CreateObject("Scripting.Dictionary")  
          
        'OPEN EXCEL FILE  
        Set xlApp = CreateObject("Excel.Application")  
        xlApp.Visible = False  
          
        'ADD YOUR EXCEL FILE PATH HERE  
        Set xlWB = xlApp.Workbooks.Open("C:\Users\Windows\Desktop\pngname.xlsx")  
        Set xlSheet = xlWB.Sheets(1)  
          
        'READ COLUMN A + B  
        lastRow = xlSheet.Cells(xlSheet.Rows.Count, 1).End(-4162).Row  
          
        For i = 2 To lastRow  'need to skip header row so start from i=2  
            If xlSheet.Cells(i, 1).Value <> "" Then  
                dict(Trim(CStr(xlSheet.Cells(i, 1).Value))) = Trim(CStr(xlSheet.Cells(i, 2).Value))  
            End If  
        Next i  
          
        'CLOSE EXCEL FILE  
        xlWB.Close False  
        xlApp.Quit  
        Set xlApp = Nothing  
          
        'LOOP THROUGH INLINE SHAPES  
        Dim ils As InlineShape  
        Dim fileName As String  
        Dim rID As String  
        Dim part As Object  
          
        For Each ils In ActiveDocument.InlineShapes  
            If ils.Type = wdInlineShapePicture Or ils.Type = wdInlineShapeLinkedPicture Then  
                On Error Resume Next  
                  
                rID = ils.Range.InlineShapes(1).LinkFormat.SourceFullName  
                If rID = "" Then  
                    rID = ils.LinkFormat.SourceFullName  
                End If  
                  
                If rID <> "" Then  
                    fileName = Mid(rID, InStrRev(rID, "") + 1)  
                      
                    If dict.Exists(fileName) Then  
                        ils.AlternativeText = dict(fileName)  
                    End If  
                End If  
                  
                On Error GoTo 0  
            End If  
        Next ils  
          
          
        Dim shp As Shape  
        For Each shp In ActiveDocument.Shapes  
            If shp.Type = msoPicture Then  
                On Error Resume Next  
                fileName = Mid(shp.LinkFormat.SourceFullName, InStrRev(shp.LinkFormat.SourceFullName, "") + 1  
                If dict.Exists(fileName) Then  
                    shp.AlternativeText = dict(fileName)  
                End If  
                On Error GoTo 0  
            End If  
        Next shp    
        MsgBox "Import successfully"  
    End Sub
    
    

    Remember to add the correct path of the Excel file into the script. You can copy the right path in File Explorer > right-click the Excel file > Copy as path.  

    Then close the VBA editor. To run the VBA script, press Alt+F8 then select the ApplyAltTextFromExcel > Run.  

    User's image

    Now all the two PNGs will be added with their corresponding descriptions in alt text. 

    I hope the information provided proves useful. Please proceed with the outlined steps and let me know whether they resolve the issue. If not, I’ll be glad to continue working with you to find a solution. 

    Thank you for your kindness and cooperation throughout this process. Should you have any questions or need further assistance, feel free to reach out at any time. 

    I look forward to your thoughts on this. 


  2. Julian, Melissa 0 Reputation points
    2025-11-21T15:38:02.03+00:00

    I've been trying to run a script that picks up the PNG file name from column A in an Excel spreadsheet and the corresponding description from column B. The goal is to use the description in column B to automatically populate the Alt Text in a Word document. However, I can't seem to get it to work. Do you have any ideas on what I might be doing wrong? it also keeps saying it is not finding the spreadsheet even through my path is correct and everything is named correctly.


  3. 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

  4. Vy Nguyen 10,130 Reputation points Microsoft External Staff Moderator
    2025-11-20T18:28:48.2566667+00:00

    Hi @Julian Melissa

    Welcome to the Microsoft Q&A forum.  

    Thank you for sharing your scenario. I understand how time-consuming it can be to manually add alt text to a large number of images across multiple Word documents, especially when accessibility compliance is a priority. 

    Microsoft Word includes built-in options like automatic alt text generation and an accessibility checker, but it does not currently support bulk mapping from external data sources, advanced automation would require custom scripts or third-party tools. Microsoft Word supports adding alternative text to images, shapes, charts, and other objects through its scripting capabilities and Microsoft 365 integration. Add alternative text to a shape, picture, chart, SmartArt graphic, or other object - Microsoft Supp… 

    To set up an automated solution, you can follow these steps: 

    1. Enable the Developer Tab in Word to access Visual Basic for Applications (VBA). 
    2. Use the InlineShape.AlternativeText property to assign alt text to images.  

    For your reference:

    1. Create a VBA script that:  
    • Loops through each image in the document. 
    • Pulls corresponding alt text from an external data source (e.g., CSV or Excel). 
    • Applies the alt text using the .AlternativeText property. 
    1. Test the script on a single document before applying it across multiple files. 

    This approach allows you to automate alt text while keeping flexibility in how your data is structured. 

    If your organization uses Microsoft 365, you can also explore Office Scripts or Power Automate for broader scalability across documents stored in OneDrive or SharePoint. Power Automate can help trigger workflows and combine data sources for advanced automation scenarios. For more details, visit the Microsoft Power Platform Community Forum

    This is a specific channel related to Power Automate. You'll get the most qualified group of respondents, and other partners who read the forums regularly can share their knowledge or learn from your interaction.   User's image

    Apologies for redirecting you to a different community as the members of the posted category focus on users with Microsoft 365 concern and have limited knowledge about Power Automate, so to get a quick and better assistance, let me redirect you in the correct way.    

    For detailed guidance, you can review Microsoft documentation on the Office JavaScript API for Word:  

    Please understand that our initial response does not always resolve the issue immediately. However, with your help and more detailed information, we can work together to find a solution.   

    I hope this information is helpful. Please follow these steps and let me know if it works for you. If not, we can work together to resolve this.    

    Thank you for your patience and your understanding. If you have any questions or need further assistance, please feel free to share them in the comments of this post so I can continue to support you. 

    I look forward to continuing the conversation.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".   

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread. 

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.