I need to do the following in a macro
If sFolderName contains ".pdf"
// Do Something
Else // Do Something
End If
but I do not know how to find out if .pdf is inside the variable or not.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In VBA, you can use the
InStrfunction to search for the position of one string inside another string.The syntax of the function is: InStr([start,]string1,string2[,compare])
In your scenario,
string1will besFolderNameandstring2would be".pdf". In other words, you are searching for the position in sFolderName where the text “.pdf” begins.If
string2is found withinstring1, thenInStrreturns the position at which match is found.For more information, please consult this MSDN page.