Quantcast
Channel: Active questions tagged crash - Stack Overflow
Viewing all articles
Browse latest Browse all 7184

PowerPoint Macro Causes Restart When Triggered from Ribbon Button (Works Fine via VBA Editor)

$
0
0

I'm facing an issue with a PowerPoint VBA macro that resizes and adjusts images on slides. Here's the problem:

When I run the macro via a button I added to the ribbon, PowerPoint restarts about every 5-6 times I click the button.When I run the exact same macro from the VBA editor (using F5), it works perfectly every time—no crashes.This issue only happens on my work computer, not on my personal computer, where it works fine regardless of how I trigger it.Does anyone have any ideas why this might be happening, or suggestions on how to debug/fix it? It seems like it could be related to memory issues or how PowerPoint interacts with the ribbon interface, but I’m not sure.

To troubleshoot, I've tried the following:

  1. Closed unnecessary programs on my work computer to ensure there are enough system resources.
  2. Simplified the macro code as much as possible, but it's already very basic—just adjusting the image size and positioning it on the slide.
Sub AdjustImageOnSlide()    SavePresentation     On Error GoTo ErrorHandler    Dim sld As slide    Dim shp As shape    Dim foundImage As Boolean    If Not ActiveWindow Is Nothing Then        If ActiveWindow.View.Type = ppViewSlide Or ActiveWindow.View.Type = ppViewNormal Then            Set sld = ActiveWindow.View.slide        Else            MsgBox "Veuillez vous assurer qu'une diapositive est active avant d'exécuter cette macro.", vbExclamation            Exit Sub        End If    ElseIf SlideShowWindows.Count > 0 Then        Set sld = SlideShowWindows(1).View.slide    Else        MsgBox "Aucune diapositive active trouvée.", vbExclamation        Exit Sub    End If    foundImage = False    For Each shp In sld.Shapes        If shp.Type = msoPicture Then            If shp.Tags.Count = 0 Or shp.Tags("Adjusted") <> "Yes" Then                shp.LockAspectRatio = msoFalse                shp.Width = 30.44 * 28.35     ' Largeur                 shp.Height = 16.19 * 28.35    ' Hauteur                 shp.Left = 2.5 * 28.35        ' 2,5 cm                shp.Top = 1 * 28.35           ' 1 cm                 shp.ZOrder msoSendToBack                shp.Tags.Add "Adjusted", "Yes"                foundImage = True                DoEvents             End If        End If    Next shp    If Not foundImage Then        MsgBox "Aucune nouvelle image à ajuster sur la diapositive.", vbInformation, "Information"    End If    Set sld = Nothing    Set shp = Nothing    Exit SubErrorHandler:    MsgBox "Une erreur s'est produite : " & Err.Description, vbCritical, "Erreur dans AdjustImageOnSlide"    Resume NextEnd Sub

Viewing all articles
Browse latest Browse all 7184

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>