다음을 통해 공유

How to run macro with parameters in Power Point?

익명
2023-10-26T08:44:33+00:00

I created a macro with two parameters in PPT as follows.

However, the macro created this way does not appear in the macro list.

Although it does not appear in the list, I saw an article saying that a macro with parameters can be entered and executed as shown in the attached photo,
but the run button is still disabled.

How to run macro with paramters in PowerPoint??

The macro code is as follows:
Dim i As Long<br>     With ActivePresentation.Slides(5).Shapes '5번 슬라이드의 모든 개체 중에서<br>         For i = 1 To .Count '각 개체를 순환하면서<br>             If .Item(i).HasTable Then '개체가 Table인 경우<br>                 .Item(i).Table.Cell(2, 3).Shape.TextFrame.TextRange.Text = ModelName<br>                 .Item(i).Table.Cell(3, 3).Shape.TextFrame.TextRange.Text = ProductType<br>             End If<br>         Next<br> End With<br> End Sub
Please tell me How.. :(
Microsoft 365 및 Office | PowerPoint | 기타 | Windows
Microsoft 365 및 Office | PowerPoint | 기타 | Windows

프레젠테이션을 만들고 멀티미디어 개체 및 텍스트를 사용한 특수 효과와 같은 그래픽 효과를 추가하는 도구를 제공하는 Microsoft 프레젠테이션 그래픽 제품군입니다.

잠긴 질문. 이 질문은 Microsoft 지원 커뮤니티에서 마이그레이션되었습니다. 질문이 도움이 되었는지 여부에 대해 응답할 수는 있지만, 메모나 회신을 추가하거나 질문을 따를 수는 없습니다.

댓글 0개 설명 없음

답변 3개

정렬 기준: 가장 유용함
  1. 익명
    2023-11-02T16:15:41+00:00

    You should create a sub routine without any parameter which calls your macro 'MyMacro' with parameters.

    If you want to call 'MyMAcro' without parameters, add 'Optional' before each parameter.

    Sub RunMyMacro()
    
        MyMacro "Name", "Type"
        
    End Sub
    
    Sub MyMacro(Optional ModelName As String, Optional ProductType As String)
    
        Dim i As Long
    
        With ActivePresentation.Slides(5).Shapes
    
            For i = 1 To .Count
    
                If .Item(i).HasTable Then
    
                    .Item(i).Table.Cell(2, 3).Shape.TextFrame.TextRange.Text = ModelName
    
                    .Item(i).Table.Cell(3, 3).Shape.TextFrame.TextRange.Text = ProductType
    
                End If
    
            Next
    
        End With
    

    End Sub

    If you want specify the two parameters at runtime, you can use InputBox to get user's parameter.

    이 대답이 도움이 되었나요?

    댓글 0개 설명 없음
  2. 익명
    2023-10-26T23:50:06+00:00

    I have created two macro modules, and the macro security settings are as shown in the attached picture.

    Still, macros that contain parameters do not appear in the Run Macro window.

    How should I run a macro that contains parameters?

    이 대답이 도움이 되었나요?

    댓글 0개 설명 없음
  3. 익명
    2023-10-26T12:05:52+00:00

    Hi

    I'm AnnaThomas and I'd happily help you with your question. In this Forum, we are Microsoft consumers just like yourself.

    If the Run button in the Macro Arguments dialog box is disabled, you may need to change macro settings in the Trust Center

    https://support.microsoft.com/office/fa2ecee4-9985-490a-9d99-74b3c726bc5a

    In the macro module, declare your parameters. For example:

    Sub MyMacro(ModelName As String, ProductType As String) Dim i As Long With ActivePresentation.Slides(5). Shapes For i = 1 To . Count If . Item(i). HasTable Then . Item(i). Table.Cell(2, 3). Shape.TextFrame.TextRange.Text = ModelName . Item(i). Table.Cell(3, 3). Shape.TextFrame.TextRange.Text = ProductType End If Next End With End Sub

    I hope this helps ;-), let me know if this is contrary to what you need, I would still be helpful to answer more of your questions.

    Best Regards,

    AnnaThomas

    Give back to the community. Help the next person with this problem by indicating whether this answer solved your problem. Click Yes or No at the bottom.

    이 대답이 도움이 되었나요?

    댓글 0개 설명 없음