Consulting

Results 1 to 2 of 2

Thread: Create Sheet if Workbook name contain some text

  1. #1

    Question Create Sheet if Workbook name contain some text

    Hi,

    i want to write a macro that will create sheet "Check" if workbook name contain "Mobile" in his name. Can someone help me please

  2. #2
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    Function Test()
      If InStr(ThisWorkbook.Name, "Check") <> 0 Then
        If Not WorkSheetExists("Mobile") Then
          Worksheets.Add After:=Worksheets(Worksheets.Count)
          ActiveSheet.Name = "Mobile"
        End If
      End If
    End Function
    
     'WorkSheetExists in a workbook:
    Function WorkSheetExists(sWorkSheet As String, Optional sWorkbook As String = "") As Boolean
        Dim ws As Worksheet, wb As Workbook
        On Error GoTo notExists
        If sWorkbook = "" Then
          Set wb = ActiveWorkbook
          Else
          Set wb = Workbooks(sWorkbook)
        End If
        Set ws = wb.Worksheets(sWorkSheet)
        WorkSheetExists = True
        Exit Function
    notExists:
        WorkSheetExists = False
    End Function

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •