application defined or object defined error while opening workbook

ashni

New Member
Joined
Jun 13, 2016
Messages
32
everytime i open my workbook this error pops up:-
run time error- 1004
application defined or object defined error


when i debug it, it takes me to the bold line i marked in red color and says :-
Cant execute code in break mode...


the code pops up the userform whenever a selected shape is moved from certain position to another. Positions based on column number.
code is saved in this workbook
Rich (BB code):
Option Explicit


Private WithEvents CmbrsEvent As CommandBars
Private Const TargetSheet As String = "Tasks" ' <== change sheet as required




Private Sub Workbook_Open()
    Dim oShp As Shape
    Application.CommandBars.FindControl(id:=549).Execute ' To snap the shapes to grid
    Call UpdateColor 'Updatecolor has to be called ones to start the timer
    For Each oShp In Sheets(TargetSheet).Shapes
        oShp.AlternativeText = oShp.Left & "*" & oShp.TopLeftCell.column
    Next
    Set CmbrsEvent = Application.CommandBars
End Sub


'to show Userform when shape is moved from InWork lane to Closed lane
Private Sub CmbrsEvent_OnUpdate()
    Dim ar() As String
    
    On Error Resume Next
    With Sheets(TargetSheet).Shapes(Selection.name)
        If TypeName(Selection) <> "Range" And Selection.Parent Is Sheets(TargetSheet) Then
            ar = Split(.AlternativeText, "*")
            If ar(0) <> CStr(.Left) And ar(1) <> CStr(.TopLeftCell.column) And ar(1) = "8" Then
                     If .TopLeftCell.column = 15 Then
                     Application.OnTime Now, Me.CodeName & ".ShowForm"
                     ElseIf .TopLeftCell.column = 16 Then
                     Application.OnTime Now, Me.CodeName & ".ShowForm"
                     ElseIf .TopLeftCell.column = 17 Then
                     Application.OnTime Now, Me.CodeName & ".ShowForm"
                     ElseIf .TopLeftCell.column = 18 Then
                     Application.OnTime Now, Me.CodeName & ".ShowForm"
                     End If
            ElseIf ar(0) <> CStr(.Left) And ar(1) <> CStr(.TopLeftCell.column) And ar(1) = "9" Then
                    If .TopLeftCell.column = 15 Then
                     Application.OnTime Now, Me.CodeName & ".ShowForm"
                     ElseIf .TopLeftCell.column = 16 Then
                     Application.OnTime Now, Me.CodeName & ".ShowForm"
                     ElseIf .TopLeftCell.column = 17 Then
                     Application.OnTime Now, Me.CodeName & ".ShowForm"
                     ElseIf .TopLeftCell.column = 18 Then
                     Application.OnTime Now, Me.CodeName & ".ShowForm"
                     End If
            ElseIf ar(0) <> CStr(.Left) And ar(1) <> CStr(.TopLeftCell.column) And ar(1) = "10" Then
                    If .TopLeftCell.column = 15 Then
                     Application.OnTime Now, Me.CodeName & ".ShowForm"
                     ElseIf .TopLeftCell.column = 16 Then
                     Application.OnTime Now, Me.CodeName & ".ShowForm"
                     ElseIf .TopLeftCell.column = 17 Then
                     Application.OnTime Now, Me.CodeName & ".ShowForm"
                     ElseIf .TopLeftCell.column = 18 Then
                     Application.OnTime Now, Me.CodeName & ".ShowForm"
                     End If
            ElseIf ar(0) <> CStr(.Left) And ar(1) <> CStr(.TopLeftCell.column) And ar(1) = "11" Then
                   If .TopLeftCell.column = 15 Then
                     Application.OnTime Now, Me.CodeName & ".ShowForm"
                     ElseIf .TopLeftCell.column = 16 Then
                     Application.OnTime Now, Me.CodeName & ".ShowForm"
                     ElseIf .TopLeftCell.column = 17 Then
                     Application.OnTime Now, Me.CodeName & ".ShowForm"
                     ElseIf .TopLeftCell.column = 18 Then
                     Application.OnTime Now, Me.CodeName & ".ShowForm"
                     End If
            End If
        End If
        .AlternativeText = .Left & "*" & .TopLeftCell.column
    End With
End Sub
Private Sub ShowForm()
      UserForm1.Label2.Caption = Selection.ShapeRange.TextFrame2.TextRange.Characters.Text
      UserForm1.Show
End Sub


please help!! I dont know what is wrong
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Check all objects are valid.

Code:
[B][COLOR=#FF0000][I]oShp.AlternativeText = oShp.Left & "*" & oShp.TopLeftCell.column[/I][/COLOR][/B]

So when it stops, in the debug area (if you are familiar with debugging) check what value oShp.Left has etc. and what oShp.TopLeftCell.Column has.

I can see it's trying to set the 'AlternativeText' (a string value.) Sometimes it's better to set the string in it's own variable and then pass that. so it would look like:

Code:
Dim s As String    
    s = CStr(oShp.Left & "*" & oShp.TopLeftCell.Column)
    oShp.AlternativeText = s
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,874
Members
452,363
Latest member
merico17

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