Hello everybody,
I'm having some Excel VBA troubles, and after no luck finding a solution, I've decided to register and post a question. So first of all; "hello" 
I'm working on a university project (using Excel 2010 in a Windows 7 Home Premium SP1) and I get the not very helpful error:
"Microsoft Visual Basic for Applications
System Error &H80004005 (-2147467259)."
Trying to identify the source of the problem, I've tried on a different computer (using Excel 2007 in a Windows 7 Enterprise SP1) and I get the slightly more helpful error:
"Microsoft Visual Basic
Run-time error '-2147467259 (80004005)':
Method 'Select' of object 'Shape' failed"
The error appears when I run the procedure that I've copied below. I've highlighted the line that Excel 2007 identifies as the source of the problem. The worksheet is currently unprotected while I work on it, that's the reason why the code to unprotect and protect it is commented out.
I have a table with similar information and the same form controls in the different rows. The user selects the row above which they want to insert a blank row and they call the procedure by clicking a form control. The puzzling thing is that most of the times it works fine, but if the user tries to insert a blank row above certain rows (and always the same rows) they get this errors. I'm at lost. Thank you for any suggestions as to what the solution can be.
Sub add_module()
'Adds a new row for a new module
Dim num_rows
Dim sel_row
Dim index
Dim column
'### It unprotects the worksheet
'Worksheets("Teaching").Unprotect
'It deactivates screen updating
Application.ScreenUpdating = False
num_rows = count_rows("Teaching", modules_table, 1)
If Not TypeName(Selection) = "Range" Then
MsgBox ("First select the row where the new module will be added (within rows " & modules_table + 2 & "-" & modules_table + num_rows & ").")
ElseIf Not Selection.Rows.Count = 1 Then
MsgBox ("First select the row where the new module will be added (within rows " & modules_table + 2 & "-" & modules_table + num_rows & ").")
ElseIf Selection.row < modules_table + 2 Or Selection.row > modules_table + num_rows Then
MsgBox ("First select the row where the new module will be added (within rows " & modules_table + 2 & "-" & modules_table + num_rows & ").")
Else
sel_row = Selection.row
'Copies the row
Worksheets("Blank").Range("1:1").Copy
Worksheets("Teaching").Rows(sel_row).Insert
'Updates the controls
For index = ActiveSheet.Shapes.Count To 1 Step -1
If ActiveSheet.Shapes(index).TopLeftCell.row = sel_row Then
column = ActiveSheet.Shapes(index).TopLeftCell.column
'Source of the problem
ActiveSheet.Shapes(index).Select
'Source of the problem
Selection.LinkedCell = number_letter(column) & sel_row
End If
Next
End If
'### It protects the worksheet
'Worksheets("Teaching").Protect
'It reactivates screen updating
Application.ScreenUpdating = True
End Sub
Bookmarks