Results 1 to 6 of 6

Thread: [RESOLVED] PowerPoint2010 - Open userform if file name contains

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2018
    Posts
    26

    Resolved [RESOLVED] PowerPoint2010 - Open userform if file name contains

    Hello,

    I am trying to come up with a vba code in PowerPoint 2010 that will execute when a particular file is open.

    What would the code be to check if the opened file name contains a particular set of words like "Analyze Data"? Prior to this name there will be a date like "January-18", but this will change monthly (obviously) and there may be different versions afterward like "v4.pptm".

    Something like:
    Code:
    Dim prs As Presentation
    For Each prs In Presentations
         If ActivePresentation 'rest of code to check if filename contains "Analayze Data" Then
              frmChecklist.Show
         End If
    Next prs

    Thank you

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: PowerPoint2010 - Open userform if file name contains

    you can use instr to get a part name, like
    Code:
    if instr(filename, "Analyze Data") > 0 then ' filename match
       ' do stuff
    end if
    if "Analyze Data" words may be separated by some other words or even additional spaces, some changes would be needed
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Mar 2018
    Posts
    26

    Re: PowerPoint2010 - Open userform if file name contains

    Is filename a variable?

    I have the below code and it's not opening the message box when it's searching for the filename. What am I missing?

    Code:
    Sub Auto_Open()
    Dim FNames As String
    Dim SearchFor As String
    Dim prs As Presentation
    
    'Open's UserForm if File labeled as "CBNA OT Risk and Control Update"
    
    SearchFor = "CBNA OT Risk and Control"
    
    For Each prs In Presentations
        If InStr(FileName, SearchFor) > 0 Then
            frmChecklist.Show
        End If
    Next prs
    
    End Sub

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: PowerPoint2010 - Open userform if file name contains

    Is filename a variable?
    i just used filename as an example

    look in the locals window to see the appropriate name for the filename of your prs object
    it may be prs.filename or just prs.name, but as i do not have powerpoint i can not check

    look in the view menu for the locals window, then drill down your object
    Last edited by westconn1; Mar 13th, 2018 at 03:48 AM.
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Mar 2018
    Posts
    26

    Re: PowerPoint2010 - Open userform if file name contains

    Hello,

    The below code does what I need.

    Code:
    Dim SearchFor As String
    Dim prs As Presentation
    
    SearchFor = "CBNA OT Risk and Control"
    
    For Each prs In Presentations
        If InStr(prs.Name, SearchFor) > 0 Then
            frmChecklist.Show
        End If
    Next prs
    Thank you

  6. #6
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: PowerPoint2010 - Open userform if file name contains

    pls mark thread resolved
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width