-
Mar 12th, 2018, 12:03 PM
#1
Thread Starter
Junior Member
[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
-
Mar 12th, 2018, 03:18 PM
#2
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
-
Mar 12th, 2018, 04:14 PM
#3
Thread Starter
Junior Member
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
-
Mar 13th, 2018, 03:44 AM
#4
Re: PowerPoint2010 - Open userform if file name contains
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
-
Mar 13th, 2018, 03:09 PM
#5
Thread Starter
Junior Member
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
-
Mar 13th, 2018, 03:10 PM
#6
Re: PowerPoint2010 - Open userform if file name contains
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|