Error Message When running code but not stepping through it.
I'm attempting to use VBA to add a Command Button to a Worksheet. When I step
through the code (using F8) it works fine. However, when I simply try to run it, Excel crashes and I get the error: The instruction at '0x650e7624' referenced memory at '0x053c831c'. The memory could not be read. Any idea what is going on? |
Error Message When running code but not stepping through it.
Hi Jared
If you are using Excel 97 then try this Try to Change the takefocusonclick property to false of the button This is a bug in Excel 97 -- Regards Ron de Bruin http://www.rondebruin.nl "Jared" wrote in message ... I'm attempting to use VBA to add a Command Button to a Worksheet. When I step through the code (using F8) it works fine. However, when I simply try to run it, Excel crashes and I get the error: The instruction at '0x650e7624' referenced memory at '0x053c831c'. The memory could not be read. Any idea what is going on? |
Error Message When running code but not stepping through it.
Ron,
I'm using Excel 2002. I should have wrote that in the first post. Sorry. "Ron de Bruin" wrote: Hi Jared If you are using Excel 97 then try this Try to Change the takefocusonclick property to false of the button This is a bug in Excel 97 -- Regards Ron de Bruin http://www.rondebruin.nl "Jared" wrote in message ... I'm attempting to use VBA to add a Command Button to a Worksheet. When I step through the code (using F8) it works fine. However, when I simply try to run it, Excel crashes and I get the error: The instruction at '0x650e7624' referenced memory at '0x053c831c'. The memory could not be read. Any idea what is going on? |
Error Message When running code but not stepping through it.
I don't see your code but this is working for me for Sheet1
Sub test() Dim WS As Worksheet Dim Btn As OLEObject Set WS = ThisWorkbook.Worksheets("Sheet1") With WS Set Btn = .OLEObjects.Add(ClassType:="Forms.CommandButton.1" , _ Left:=.Range("C3").Left, Top:=.Range("C3").Top, _ Width:=100, Height:=30) End With Btn.Object.Caption = "Click Me" Btn.Name = "YourButton" With ThisWorkbook.VBProject.VBComponents(WS.CodeName).C odeModule .InsertLines .CreateEventProc("Click", Btn.Name) + 1, _ vbTab & "If Range(""A1"").Value 0 Then " & vbCrLf & _ vbTab & vbTab & "Msgbox ""Hi""" & vbCrLf & _ vbTab & "End If" End With End Sub -- Regards Ron de Bruin http://www.rondebruin.nl "Jared" wrote in message ... Ron, I'm using Excel 2002. I should have wrote that in the first post. Sorry. "Ron de Bruin" wrote: Hi Jared If you are using Excel 97 then try this Try to Change the takefocusonclick property to false of the button This is a bug in Excel 97 -- Regards Ron de Bruin http://www.rondebruin.nl "Jared" wrote in message ... I'm attempting to use VBA to add a Command Button to a Worksheet. When I step through the code (using F8) it works fine. However, when I simply try to run it, Excel crashes and I get the error: The instruction at '0x650e7624' referenced memory at '0x053c831c'. The memory could not be read. Any idea what is going on? |
Error Message When running code but not stepping through it.
I don't know why, but when I changed the location of it in my code it worked
fine. "Ron de Bruin" wrote: I don't see your code but this is working for me for Sheet1 Sub test() Dim WS As Worksheet Dim Btn As OLEObject Set WS = ThisWorkbook.Worksheets("Sheet1") With WS Set Btn = .OLEObjects.Add(ClassType:="Forms.CommandButton.1" , _ Left:=.Range("C3").Left, Top:=.Range("C3").Top, _ Width:=100, Height:=30) End With Btn.Object.Caption = "Click Me" Btn.Name = "YourButton" With ThisWorkbook.VBProject.VBComponents(WS.CodeName).C odeModule .InsertLines .CreateEventProc("Click", Btn.Name) + 1, _ vbTab & "If Range(""A1"").Value 0 Then " & vbCrLf & _ vbTab & vbTab & "Msgbox ""Hi""" & vbCrLf & _ vbTab & "End If" End With End Sub -- Regards Ron de Bruin http://www.rondebruin.nl "Jared" wrote in message ... Ron, I'm using Excel 2002. I should have wrote that in the first post. Sorry. "Ron de Bruin" wrote: Hi Jared If you are using Excel 97 then try this Try to Change the takefocusonclick property to false of the button This is a bug in Excel 97 -- Regards Ron de Bruin http://www.rondebruin.nl "Jared" wrote in message ... I'm attempting to use VBA to add a Command Button to a Worksheet. When I step through the code (using F8) it works fine. However, when I simply try to run it, Excel crashes and I get the error: The instruction at '0x650e7624' referenced memory at '0x053c831c'. The memory could not be read. Any idea what is going on? |
All times are GMT +1. The time now is 11:37 AM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com