Excel/Excel VBA


Hello, Tom! My question is about scenario which doesn't work correctly in the only one version of MS Office.(32-bit, MS Excel 2010, 14.0.7143.5000). It does work on all other versions.
My code is next:

Public Sub main_dopolnenie()
Dim sh1 As Worksheet
Dim wb1 As Workbook
Dim rg1 As Range
Dim CopyObjectsWithCells As Boolean

On Error GoTo errhandler

CopyObjectsWithCells = Application.CopyObjectsWithCells
Application.CopyObjectsWithCells = True

Set rg1 = Windows(ActiveWorkbook.Name).ActiveCell
Set wb1 = ActiveWorkbook
Set sh1 = ActiveWorkbook.ActiveSheet

   InsertSheet wb1

   wb1.Sheets(ServiceSheetName).Paste Destination:=wb1.Sheets(ServiceSheetName).Range("A1")
   SelectShapes wb1.Sheets(ServiceSheetName)
   DeleteSheet wb1

   If Windows(wb1.Name).Selection.ShapeRange.Item(1).Top > Height_Dopolnenie Then Windows(wb1.Name).Selection.ShapeRange.IncrementTop -50
Application.CopyObjectsWithCells = CopyObjectsWithCells
Exit Sub

An error occurs in the line:
If Windows(wb1.Name).Selection.ShapeRange.Item(1).Top > Height_Dopolnenie Then Windows(wb1.Name).Selection.ShapeRange.IncrementTop -50

438ProjectObject doesn't support this property or method. I can't understand why. This error occurs on both computers with defined version of excel. Thank you for help.


the property  CopyObjectsWithCells  was introduced in Excel 2013.  So it would raise an error in Excel 2010.  You have on error set so this may be hiding where your actual error is.  You should remove or comment out error handling when you debug.  

It would be impossible for me to see the flow of your code since I can't see your error handler or the procedure you seem to be calling.  I think you will have to do the debugging to find where your real problem is.  

Also, in the line


if that is in fact raising an error, then you would need to determine what is selected at that time.  Possibly you did some macro recording and this is what is recorded, but it is rare that you would want to use "selection" to do any "work" because with if statements and so forth you would have not real knowledge of what is selected.

That is the best advice I can give you with what I can see (which isn't much but don't come back and post a lot more code, because this appears to be something related to what version of excel you are using rather than what line of code you are using and there is no way I can debug that).

Tom Ogilvy  
About Excel
This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here


All Answers

Answers by Expert:

Ask Experts


Tom Ogilvy


Selected as an Excel MVP by Microsoft since 1999. Answering Excel questions in Allexperts since its inception in 2001. Able to answer questions on almost all aspects of Excel's internal capabilities. If seeking a VBA solution, please specify that in your question itself so I give you the answer you want. [Excel has weak protection - if you are distributing an application, I don't answer questions on how to protect your project from your users.]


Extensive experience.

Master of Science (MS) degree Operations Research (ORSA)

Awards and Honors
Microsoft MVP in Excel.

©2017 About.com. All rights reserved.