Consulting

Results 1 to 6 of 6

Thread: activate an already open workbook or open if not open

  1. #1
    VBAX Regular
    Joined
    Sep 2013
    Posts
    37
    Location

    activate an already open workbook or open if not open

    fname = "\\pmi.corp\dfsroot\HumanDev\QA\Staff\MPP\Leadership Reporting\MPP-All Data Combined File (Work Pending).xlsx"

    Workbooks.Open Filename:=fname, UpdateLinks:=0





    How would I go about writing an if statement saying to activate this workbook if its open or open it if its not?

  2. #2
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,646
    getobject(fname)

  3. #3
    VBAX Regular
    Joined
    Sep 2013
    Posts
    37
    Location
    fname = "\\pmi.corp\dfsroot\HumanDev\QA\Staff\MPP\Leadership Reporting\MPP-All Data Combined File (Work Pending).xlsx"


    If WBisOpen(fname) Then


    Else
    Workbooks.Open Filename:=fname, UpdateLinks:=0

    End If

    then I just called the function

    Function WBisOpen(fname As String) As Boolean
    Dim wb As Workbook
    On Error Resume Next
    Set wb = Workbooks(fname)
    On Error GoTo 0
    WBisOpen = Not wb Is Nothing
    End Function

  4. #4
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,646
    Can you please wrap VBA code in code tags ?

    Did you read post #2 ?

  5. #5
    VBAX Regular
    Joined
    Sep 2013
    Posts
    37
    Location
    Quote Originally Posted by snb View Post
    Can you please wrap VBA code in code tags ?

    Did you read post #2 ?
    Ya. It didnt work. It like opened it but it wouldn't activate the workbook. Also how do u wrap code in tags?

  6. #6
    VBAX Regular
    Joined
    Sep 2013
    Posts
    37
    Location
    Quote Originally Posted by snb View Post
    Can you please wrap VBA code in code tags ?

    Did you read post #2 ?
    I tries but it didn't work. It opened the workbook one time but then it just disapeared. Also how do I wrap the code in tags?

Posting Permissions

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