Consulting

Results 1 to 6 of 6

Thread: VBA Code required to see if workbook is opened or not.

  1. #1
    VBAX Regular
    Joined
    Sep 2017
    Posts
    7
    Location

    VBA Code required to see if workbook is opened or not.

    I want the vba code to check if workbook is opened or not. my workbook name is FER Tracker 15-16. i want to match it with opened with partially "FER Tracker*"

    if it is opened then show message box "1st OPEN fer tracker" & terminate procedure.

    if found opened . then next statement excutes as it is.


    Thanks in advance.

  2. #2
    VBAX Expert
    Joined
    Sep 2016
    Posts
    788
    Location
    Option Explicit
    
    
    Sub test()
        Dim wb As Workbook
        
        For Each wb In Workbooks
            If wb.Name Like "FER Tracker*" Then
                MsgBox wb.Name
                Exit For
            End If
        Next
        
    End Sub

    マナ

  3. #3
    VBAX Regular
    Joined
    Sep 2017
    Posts
    7
    Location
    Quote Originally Posted by mana View Post
    Option Explicit
    
    
    Sub test()
        Dim wb As Workbook
        
        For Each wb In Workbooks
            If wb.Name Like "FER Tracker*" Then
                MsgBox wb.Name
                Exit For
            End If
        Next
        
    End Sub

    マナ
    Hi Mana,

    i want code like below.
    sub test ()
    dim wb as workbook
    for each wb in workbook
    if not wb.name like "FER Tracker*" then
    msgbox "FER Tracker is not opened"
    exit sub 'to teminate the whole procedure.
    end if
    next wb
    end sub

  4. #4
    VBAX Expert
    Joined
    Sep 2016
    Posts
    788
    Location
    >i want code like below.

    I can't understand what is your problem.

  5. #5
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,730
    Location
    Quote Originally Posted by Pravina View Post
    Hi Mana,

    i want code like below.
    sub test ()
    dim wb as workbook
    for each wb in workbook
    if not wb.name like "FER Tracker*" then
    msgbox "FER Tracker is not opened"
    exit sub 'to teminate the whole procedure.
    end if
    next wb
    end sub

    Sub test()
    
        Dim bWorkbookOpen As Boolean
        Dim wb As Workbook
    
        bWorkbookOpen = False
    
        For Each wb In applicatiom.Workbooks
            If wb.Name Like "FER Tracker*" Then bWorkbookOpen = True
        Next
    
        If Not bWorkbookOpen Then
            MsgBox "1st OPEN fer tracker"
            Exit Sub
        End If
        
        
    '   continue
    
    End Sub
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  6. #6
    VBAX Regular
    Joined
    Sep 2017
    Posts
    7
    Location
    Quote Originally Posted by Paul_Hossler View Post
    Sub test()
    
        Dim bWorkbookOpen As Boolean
        Dim wb As Workbook
    
        bWorkbookOpen = False
    
        For Each wb In applicatiom.Workbooks
            If wb.Name Like "FER Tracker*" Then bWorkbookOpen = True
        Next
    
        If Not bWorkbookOpen Then
            MsgBox "1st OPEN fer tracker"
            Exit Sub
        End If
        
        
    '   continue
    
    End Sub

    Thank you very much Paul for your support.

Posting Permissions

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