VBA query - keeps opening another spreadsheet

MOB

Well-known Member
Joined
Oct 18, 2005
Messages
1,066
Office Version
  1. 365
Platform
  1. Windows
Firstly, I am not a VBA whizz by any means, I know just a little bit and get by............

I have this code which I have copied from another spreadsheet, and pasted into sheet3 in "view code"

Code:
Sub Auto_Open()
    On Error Resume Next
    Application.OnDoubleClick = "updateFromLeft"
 
End Sub
Sub updateFromLeft()

    Dim WasProtected As Boolean
    On Error GoTo myhandler
 
    If ActiveCell.Row = 4 And ActiveCell.Column > 9 And ActiveCell.Column < 40 Then
    
 Dim response As VbMsgBoxResult
response = MsgBox("Are you sure you want to copy yesterday's data over?", vbYesNo)
If response = vbNo Then Exit Sub
         
        If ThisWorkbook.ActiveSheet.ProtectContents = True Then
            ThisWorkbook.ActiveSheet.Unprotect Password:="grange"
            WasProtected = True
        Else
            WasProtected = False
        End If
            ActiveCell.Offset(, -1).EntireColumn.Copy Destination:=ActiveCell.EntireColumn
        If WasProtected Then ThisWorkbook.ActiveSheet.Protect Password:="grange"
        Exit Sub
    Else
        Application.SendKeys "{F2}"
        Exit Sub
    End If
 
myhandler:
    If Application.ScreenUpdating <> True Then Application.ScreenUpdating = True
    Application.SendKeys "{F2}"
End Sub

When I double click to activate the code, the first thing it does is open the spreadsheet that I copied the code from, but I just want it to run the code!

How does it know the location of the other spreadsheet? What am I missing?

TIA
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
The code you posted should be in a General module not a Worksheet module. You will need to save, close and reopen the workbook for the Auto_Open procedure to run. Currently the procedure in the original workbook is assigned to the OnDoubleClick property.
 
Upvote 0

Forum statistics

Threads
1,225,070
Messages
6,182,667
Members
453,131
Latest member
BeLocke

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