This VBA code, titled "UpdateTextboxesFromExcel," is designed to interact with both Microsoft Excel and PowerPoint to read a specific cell value from an Excel workbook and update a textbox in each slide of an active PowerPoint presentation with that value. Break down of what the code is trying to do below:
1. Declare Variables: excelApp: Object variable for the Excel application. wb: Object variable for the Excel workbook. ws: Object variable for the Excel worksheet (sheet 1 in this case). excelFilePath: String variable containing the path to the Excel file. cellValue: Variant variable to store the value read from Excel. slide: Object variable to iterate through each slide in the PowerPoint presentation.
- Set Excel File Path: Specify the path to the Excel file (excelFilePath) you want to read data from.
2. Create Excel Application and Open Workbook: Create a new instance of the Excel application using CreateObject("Excel.Application"). Open the Excel workbook located at excelFilePath using excelApp.Workbooks.Open(excelFilePath). Set ws to refer to the first worksheet (assuming data is on the first sheet).
3. Read Data from Excel: Read the value from cell J316 of the Excel worksheet and store it in the cellValue variable using ws.Range("J316").Value.
4. Display Message Box: Show a message box with the value read from Excel using MsgBox.
5. Iterate Through PowerPoint Slides: Loop through each slide in the active PowerPoint presentation using a For Each loop. Check if a textbox named "TextBox 1" exists on the current slide using the ShapeExists function. If the textbox exists, update its text with the value from Excel formatted as a percentage (e.g., "50.00%"). Display a message box indicating which slide is being updated.
6. Clean Up: Close the Excel workbook without saving changes (wb.Close False). Quit the Excel application (excelApp.Quit). Set objects (ws, wb, excelApp) to Nothing to release resources and free up memory.
7. ShapeExists Function: This is a helper function that checks if a shape with a specified name exists on a given slide. It uses error handling to handle cases where the shape may not exist, returning True if the shape exists and False otherwise.
VBA code below:
Sub UpdateTextboxesFromExcel()
Dim excelApp As Object
Dim wb As Object
Dim ws As Object
Dim excelFilePath As String
Dim cellValue As Variant
Dim slide As Object
' Path to the Excel file
excelFilePath = "\\sydfpr05a\IPG\AUS-MBW\_Initiative\Clients\2023\IAG\_Comms Design\Charlie Dox\INI-VENTORS\Ini Ventors Draft Excel V1.xlsm"
' Create a new Excel application and open the workbook
Set excelApp = CreateObject("Excel.Application")
Set wb = excelApp.Workbooks.Open(excelFilePath)
Set ws = wb.Sheets(1) ' Assuming data is on the first sheet
' Read data from cell J316
cellValue = ws.Range("J316").Value
' Display a message box with the value read from Excel
MsgBox "Read from Excel: " & cellValue
' Iterate through each slide in the PowerPoint presentation
For Each slide In ActivePresentation.Slides
' Check if the textbox named "TextBox 1" exists in the slide
If ShapeExists("TextBox 1", slide) Then
' Update the textbox text with data from Excel
slide.Shapes("TextBox 1").TextFrame.TextRange.Text = Format(cellValue, "0.00%")
' Display a message box indicating the textbox is being updated
MsgBox "Updating TextBox 1 on slide " & slide.SlideIndex
End If
Next slide
' Clean up
wb.Close False
excelApp.Quit
Set ws = Nothing
Set wb = Nothing
Set excelApp = Nothing
End Sub
Function ShapeExists(shapeName As String, slide As Object) As Boolean
Dim shp As Object
On Error Resume Next
Set shp = slide.Shapes(shapeName)
On Error GoTo 0
ShapeExists = Not shp Is Nothing
End Function
Problem: The macro appears to understand what excel path to look at but it's not updating the textbook with the data from the excel cell I have identified. If anyone could advise where I may be going wrong that would be great :)

Rectangle 1orTextBox n.MsgBox "Updating TextBox 1 on slide "? If not, it meansShapeExists()returnFalse. The only reason I can speculate is a mismatched name.J316is a blank cell. So nothing is in Textbox 1.