• Macros are not working (2002 SP3)

    Author
    Topic
    #424880

    I would be very grateful for some help from someone a lot more knowledgable than me.

    I recorded six macros to speed up some very tedious jobs and none of them seem to now work when I click on the buttons I created for each of them on the toolbar (using Customize).

    I recorded them because I can’t write the language to save myself … which is probably half the problem!

    The macros are attached in the text file. Any help would be really appreciated!

    Viewing 1 reply thread
    Author
    Replies
    • #977081

      Here is a macro for #1 (insert a blank slide):

      Sub InsertBlankSlide()
      ActivePresentation.Slides.Add _
      Index:=ActivePresentation.Slides.Count + 1, _
      Layout:=ppLayoutBlank
      End Sub

      The other macros work OK, but perhaps they do not do what you intended. What did you want to accomplish?

      • #977122

        Thank you very much Hans.

        As I suspected, the problem is that I can’t write code and my macro recording seems not to have worked. What I am trying to achieve with the remaining macros is as follows:

        2. Resize an inserted picture on the slide as 19 cm Height and 14.25cm Width
        3. Resize an inserted picture on the slide as 7.5cm Height and 10cm Width
        4. Resize an inserted picture on the slide as 10cm Height and 7.5cm Width

        5. Insert two buttons onto the slide, coloured dark grey, one a backward arrow (Horizontal position 22.2cm from Top Left Corner and Vertical position 17.5cm from Top Left Corner), the other a forward arrow (Horizontal position 23.5cm from Top Left Corner and Vertical position 17.5cm from Top Left Corner), each button’s dimensions 1 cm Height and 1.06 cm Width.

        6. Insert a text box with any text onto the slide, with font colour white, background colour black, font Comic Sans 20 point Bold, text centred.

        I also tried to record a macro to Insert Picture from a File and navigate to a specific folder, but I couldn’t record it.

        I really appreciate your help Hans.

        • #977127

          For #2/3/4, you can use

          Sub Resize2()
          ResizePicture 19, 14.25
          End Sub

          Sub Resize3()
          ResizePicture 7.5, 10
          End Sub

          Sub Resize4()
          ResizePicture 10, 7.5
          End Sub

          Sub ResizePicture(dblHeight As Double, dblWidth As Double)
          On Error Goto ExitHandler
          With ActiveWindow.Selection.ShapeRange
          .LockAspectRatio = False
          .Height = dblHeight * 72 / 2.54
          .Width = dblWidth * 72 / 2.54
          End With
          End Sub

          ResizePicture multiplies with 72/2.54 to convert from centimetres to points. The macros Resize2, Resize3 and Resize4 are the ones to place on a toolbar.

          #5 and #6 work for me – the code could be streamlined, but it does what you describe.

          Here is a macro that lets the user select a picture file from a specific folder:

          Sub LoadPicture()
          With Application.FileDialog(msoFileDialogFilePicker)
          .Filters.Add "Images", "*.bmp; *.gif; *.jpg; *.png"
          .InitialFileName = "C:Images"
          If .Show = True Then
          ActiveWindow.Selection.SlideRange.Shapes.AddPicture _
          FileName:=.SelectedItems(1), LinkToFile:=False, _
          SaveWithDocument:=True, Left:=10, Top:=10
          End If
          End With
          End Sub

      • #977123

        Hans, I must be doing something wrong, but I copied and pasted your code to replace my “Insert New Slide” macro, but my custom button assigned to that macro still does nothing when I click it.

        • #977128

          The following works for me:

          • Select Tools | Customize…
          • Activate the Commands tab of the Customize window.
          • Select Macros in the list of Categories on the left hand side.
          • Select InsertBlankSlide in the list of Commands on the right hand side*.
          • Drag this to the desired position on a built-in or custom toolbar.
          • Close the Customize window**.
          • Click the button to test it.
            [/list]* If InsertBlankSlide is not available, you haven’t put the macro in the correct place.
            ** You can later return to the Customize window to modify the new button (right-click it to change its caption, style, etc.)
          • #977131

            Thanks Hans. That is exactly how I added the custom button, so the cause was something else. I checked on the Securiy settings and Macro Security was set to the default, which is High … sorry, I should have checked this first when it didn’t run.
            All your help is much appreciated (as always)!!

    • #977268

      useful,

      Interesting thread….. it’s really tedious inserting a picture and re-sizing it, or new slide > layout, so I can understand your need to ‘try the macro’ thing.

      I find Steve R’s…. page on how to use this vba/macro stuff in powerpoint really useful…

      How do I use VBA code in PowerPoint?

      Cheers

      • #977271

        Tedious is a pretty good description … also time consuming! The main thing is that I now have all my macros working (silly security defaults!) and it has slightly reduced the tedium. Thanks for your suggestions. It’s a great pleasure to have access to such knowlegable people.

    Viewing 1 reply thread
    Reply To: Macros are not working (2002 SP3)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: