instead of "like", the function you're looking for is Instr() so, your macro should look something like: Sub Test() Dim wb As Workbook Dim DestinationFile As String, SourceFile As String For Each wb In Workbooks If (InStr(1, wb.Name, "D") > 0) Then DestinationFile = wb.Name ElseIf (InStr(1, wb.Name, "M") > 0) Then SourceFile = wb.Name End If Next wb MsgBox "DestinationFile: " & SourceFile & Chr(13) & "DestinationFile: " & SourceFile End Sub Paul----------------------------------------- “Do all the good you can, By all the means you can, In all the ways you can, In all the places you can, At all the times you can, To all the people you can, As long as ever you can.” - John Wesley -----------------------------------------
On Wednesday, May 4, 2016 11:53 AM, Nitin Balodi <nitinbal...@live.com> wrote: <!--#yiv6559717754 .yiv6559717754hmmessage P{margin:0px;padding:0px;}#yiv6559717754 body.yiv6559717754hmmessage{font-size:12pt;font-family:Calibri;}-->Hi All, I am trying to browse through all open workbooks and assign their names to variables based on some pattern. Below is the code I have written: Sub Test() Dim wb As Workbooks For Each wb In Workbooks If Workbook.Name Like "*123*" Then DestinationFile = ActiveWorkbook.Name ElseIf Workbook.Name Like "*456*" Then SourceFile = ActiveWorkbook.Name End IfNextMsgBox DestinationFile MsgBox SourceFile End Sub Can someone help me on this. Regards. Yours Sincerely,Nitin Balodi -- Are you =EXP(E:RT) or =NOT(EXP(E:RT)) in Excel? And do you wanna be? It’s =TIME(2,DO:IT,N:OW) ! Join official Facebook page of this forum @ https://www.facebook.com/discussexcel FORUM RULES 1) Use concise, accurate thread titles. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get quick attention or may not be answered. 2) Don't post a question in the thread of another member. 3) Don't post questions regarding breaking or bypassing any security measure. 4) Acknowledge the responses you receive, good or bad. 5) Jobs posting is not allowed. 6) Sharing copyrighted material and their links is not allowed. NOTE : Don't ever post confidential data in a workbook. Forum owners and members are not responsible for any loss. --- You received this message because you are subscribed to the Google Groups "MS EXCEL AND VBA MACROS" group. To unsubscribe from this group and stop receiving emails from it, send an email to excel-macros+unsubscr...@googlegroups.com. To post to this group, send email to excel-macros@googlegroups.com. Visit this group at https://groups.google.com/group/excel-macros. For more options, visit https://groups.google.com/d/optout. -- Are you =EXP(E:RT) or =NOT(EXP(E:RT)) in Excel? And do you wanna be? It’s =TIME(2,DO:IT,N:OW) ! Join official Facebook page of this forum @ https://www.facebook.com/discussexcel FORUM RULES 1) Use concise, accurate thread titles. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get quick attention or may not be answered. 2) Don't post a question in the thread of another member. 3) Don't post questions regarding breaking or bypassing any security measure. 4) Acknowledge the responses you receive, good or bad. 5) Jobs posting is not allowed. 6) Sharing copyrighted material and their links is not allowed. NOTE : Don't ever post confidential data in a workbook. Forum owners and members are not responsible for any loss. --- You received this message because you are subscribed to the Google Groups "MS EXCEL AND VBA MACROS" group. To unsubscribe from this group and stop receiving emails from it, send an email to excel-macros+unsubscr...@googlegroups.com. To post to this group, send email to excel-macros@googlegroups.com. Visit this group at https://groups.google.com/group/excel-macros. For more options, visit https://groups.google.com/d/optout.