Make this macro open a workbook?

bpflyr

Board Regular
Joined
Nov 7, 2005
Messages
116
I have this macro (was given to me by you wizards!):

Sub GetData()
Application.ScreenUpdating = False
Windows("BDataEntry.xls").Activate
Sheets("Data Entry").Select
Range("A3:AF20").Copy
Windows("BLogbook.xls").Activate
Sheets("Log Entry").Select
Cells(Rows.Count, 1).End(xlUp)(2, 1).PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=True _
, Transpose:=False
With Application
.ScreenUpdating = True
.CutCopyMode = False
End With
End Sub


Is there a way that it can open BDataEntry automatically. Right now it appears that if BDataEntry is not already open and I try to run the macro, I get a "subscript out of range" error message. If BDataEntry is open all works great. It would be cool though if the macro would open it for me. Is there a way?
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).

acw

MrExcel MVP
Joined
Feb 13, 2004
Messages
4,814
Hi

You could build your own function to see if the workbook is open and action accordingly

Code:
Function IsOpen(wb)
  IsOpen = False
  For Each ce In Workbooks
    If ce.Name = wb Then
     IsOpen = True
    End If
 Next ce
End Function

Then change

Windows("BDataEntry.xls").Activate

to

if isopen("BDataEntry.xls") then
Windows("BDataEntry.xls").Activate
else
workbooks.open("c:\temp\BDataEntry.xls")
end if

Change the path name as required.


HTH

Tony
 

acw

MrExcel MVP
Joined
Feb 13, 2004
Messages
4,814
Hi

Just put it in the same module as the existing code.


Tony
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,018
Messages
5,834,976
Members
430,331
Latest member
Syed Yasir Hannan

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
Top