PDA

View Full Version : activate an already open workbook or open if not open



jmutsche
12-10-2013, 10:43 AM
fname = "\\pmi.corp\dfsroot\HumanDev\QA\Staff\MPP\Leadership (file://\\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?

snb
12-10-2013, 11:00 AM
getobject(fname)

jmutsche
12-10-2013, 11:03 AM
fname = "\\pmi.corp\dfsroot\HumanDev\QA\Staff\MPP\Leadership (file://\\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

snb
12-10-2013, 01:30 PM
Can you please wrap VBA code in code tags ?

Did you read post #2 ?

jmutsche
12-10-2013, 05:48 PM
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?

jmutsche
12-10-2013, 05:52 PM
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?