If Workbook path contains then

pltom55

New Member
Joined
Oct 6, 2014
Messages
27
I need help with using "contains" in code.

What is mean is. When i open up a workbook using vba, I have its directory and pathname.

How would i write something along these lines?



If [workbookpath] contains [word im looking for] Then
blah blah



Thanks
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
contains is not a VBA comparative, like it is in AppleScript.

I think this code will show one way of doing it in VBA.

Code:
If Instr(1, "big long string", "long") <> 0 Then
    "long is inside"
Else
    "no Long in big string"
End If
 
Upvote 0
To find text in your path, searching for the word 'user' in my example


Code:
Sub getpath()

Dim docpath As String
docpath = Application.ActiveWorkbook.Path
If docpath Like "*user*" Then
MsgBox "FOUND IT"
Else: MsgBox "not found"

End If
End Sub

You could also use the full name if you want to with Application.ActiveWorkbook.FullName
 
Upvote 0
By the way bugmonsta the "user" is case sensative.
Any way to get around that and just search for the word
 
Upvote 0
A typical way to make a test case insensitive would be

Code:
If UCase(docpath) Like UCase("*user*") Then
 
Upvote 0

Forum statistics

Threads
1,215,465
Messages
6,124,975
Members
449,200
Latest member
Jamil ahmed

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top