Guest User

Untitled

a guest
Dec 10th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. Sub PartialWorkbookName()
  2.  
  3. Const cStrPartial As String = "Website_20"
  4.  
  5. Dim wb As Workbook
  6. Dim objWb As Workbook
  7.  
  8. For Each wb In Workbooks
  9. If Left(wb.Name, Len(cStrPartial)) = cStrPartial Then
  10. Set objWb = Workbooks(wb.Name)
  11. Exit For
  12. End If
  13. Next
  14. If objWb Is Nothing Then GoTo NotFound
  15.  
  16. With objWb
  17. ' Code in here
  18.  
  19.  
  20. End With
  21.  
  22. Set objWb = Nothing
  23.  
  24. Exit Sub
  25. NotFound:
  26. MsgBox "Workbook not found."
  27. End Sub
Add Comment
Please, Sign In to add comment