Opening or activate files using macro

Ringo71

New Member
Joined
Oct 24, 2014
Messages
7
Is there a way to have a macro find if a workbook is open before running code to open the file and skip opening if it is and vice versa?

This is a sample of something that i tried and failed

If (Windows("Gator.xlsm").Activate = False) Then Workbooks.Open Filename _
:= _
"https://d.docs.live.net/7c26cd2da69fba08/Documents/Johnny%Gator%20Docs/Gator%20Data%202013.xlsm", UpdateLinks:=0
If (Windows("Gator Data 2013.xlsm").Activate = True) Then Windows("Gator Data 2013.xlsm").Activate

Also, I've seen some people insert a copy of their vba code how is that done?

Thank you
Ringo
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
You can call this function from the macro that opens the workbook to see if it is already open.
Code:
Function WorkbookOpen(WorkBookName As String) As Boolean
' returns TRUE if the workbook is open
    WorkbookOpen = False
    On Error GoTo WorkBookNotOpen
    If Len(Application.Workbooks(WorkBookName).Name) > 0 Then
        WorkbookOpen = True
        Exit Function
    End If
WorkBookNotOpen:
End Function
 
Upvote 0

Forum statistics

Threads
1,203,610
Messages
6,056,296
Members
444,855
Latest member
archadiel

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top