ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Requesting Help (yes again) Translating a Macro into VB.Net Code (https://www.excelbanter.com/excel-programming/396395-requesting-help-yes-again-translating-macro-into-vbulletin-net-code.html)

eBob.com[_3_]

Requesting Help (yes again) Translating a Macro into VB.Net Code
 
I've learned that after inserting a picture into my spreadsheet (which I am
creating in a VB.Net program) I have to adjust it's size. So I recorded a
macro to so and ended up with the following:

Sub sizepic()
'
' sizepic Macro
' Macro recorded 8/27/2007 by John Smith
'

'
ActiveSheet.Shapes("Picture 4").Select
Selection.ShapeRange.LockAspectRatio = msoTrue
Selection.ShapeRange.Height = 110.25
Selection.ShapeRange.Width = 65.25
Selection.ShapeRange.Rotation = 0#
End Sub


I think that ActiveSheet here corresponds to "objSheet" in my program (Dim
objSheet As Excel._Worksheet). But when I translate this to this VB.Net
statement ...
objSheet.Shapes("Picture " + XLRow.ToString).select()
the VS IDE complains that: "Interface 'Excel.Shapes' cannot be indexed
because it has no default property."

So I scratch my head, fumble around, and find that the following (which
seemed reasonable at the time!) compiles and builds without error:
objSheet.Shapes().select("picture " + XLRow.ToString)
But it results in runtime error: Public member 'select' on type 'Shapes' not
found.

The remainder of the code which I have derived from the above is ...
objSheet.Shapes.lockaspectratio = msotrue
objSheet.Shapes.height = 110.25
objSheet.Shapes.width = 65.25

That compiles and builds OK (except that I have to determine the value of
"msotrue") but I sort of expect runtime errors. I can't use
objSheet.Selection because the IDE says that 'Selection' is not a member of
Excel._Worksheet).

So ... any further assistance you guys can provide would be much
appreciated. Thanks, Bob




[email protected][_2_]

Requesting Help (yes again) Translating a Macro into VB.Net Code
 
When you run the recorded macro, sizepic(), "Picture 4" already
exists, your only selecting it.

It looks like your code might work if you know for certain
XLRow.ToString() is 4 and from within C++ you're opening the Workbook
that has a "Picture 4" Shape.

If you are creating the Workbook dynamically then the problem is that
you don't have a shape object of name "Picture " + XLRow.ToString() .

Supposing you have added it then the problem is that you used a
barebones API to create the Shape and the Shape doesn't yet know it's
supposed to be a Picture.




All times are GMT +1. The time now is 11:38 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com