Previous in Forum: Carpooling Phone App   Next in Forum: Schneider DDC Programming
Close
Close
Close
4 comments
Rate Comments: Nested
Power-User

Join Date: Feb 2011
Location: Shimurali, Westbengal,India
Posts: 119

VBA (Excel 2007) Shape Handling

04/16/2013 3:39 AM

In excel 2007, I copy a shape from one sheet and paste it to another sheet using VBA. Now, I want to paste a rectangular shape with the shape previously pasted. The rectangular box contain the Id name of the shape pasted(ID shall be feed from user). Please help me how I can edit the text within the rectangular box using VBA. For example, I paste a shape of transformer with relevent data shall be provided in a massage box like Trafo Id, MVA etc.Now transformer Id shall be indicate in the rectangular box using VBA is my target.

Please help me.

Register to Reply
Interested in this topic? By joining CR4 you can "subscribe" to
this discussion and receive notification when new comments are added.

Good Answers:

These comments received enough positive votes to make them "good answers".
3
Power-User

Join Date: Oct 2008
Location: Troy, NY
Posts: 122
Good Answers: 4
#1

Re: VBA (Excel 2007) Shape Handling

04/16/2013 9:22 AM

One thing you can try is to use the Record Macro feature in Excel. For example, I recorded this macro of inserting a text box and adding text into it on an Excel worksheet. You can view the code that the recording creates by going to the VBA Editor. (Alt-F11)

Sub Macro2()

'

' Macro2 Macro

'

'

ActiveSheet.Shapes.AddTextbox(msoTextOrientationHorizontal, 682.5, 78, 340.5, _

130.5).Select

Selection.ShapeRange(1).TextFrame2.TextRange.Characters.Text = _

"This is a test."

Selection.ShapeRange(1).TextFrame2.TextRange.Characters(1, 15).ParagraphFormat. _

FirstLineIndent = 0

With Selection.ShapeRange(1).TextFrame2.TextRange.Characters(1, 15).Font

.NameComplexScript = "+mn-cs"

.NameFarEast = "+mn-ea"

.Fill.Visible = msoTrue

.Fill.ForeColor.ObjectThemeColor = msoThemeColorDark1

.Fill.ForeColor.TintAndShade = 0

.Fill.ForeColor.Brightness = 0

.Fill.Transparency = 0

.Fill.Solid

.Size = 11

.Name = "+mn-lt"

End With

End Sub

Register to Reply Good Answer (Score 3)
Power-User

Join Date: Feb 2011
Location: Shimurali, Westbengal,India
Posts: 119
#2
In reply to #1

Re: VBA (Excel 2007) Shape Handling

04/17/2013 4:32 AM

Selection.ShapeRange(1).TextFrame2.TextRange.Characters.Text = _
"This is a test."

This line shows an error

Object doesn't support this property or method (Error 438)

Please help me.

Register to Reply
Associate
India - Member - New Member

Join Date: Dec 2006
Location: Ahmedabad, Gujarat State, India
Posts: 32
#3
In reply to #2

Re: VBA (Excel 2007) Shape Handling

04/17/2013 7:30 AM

Hi!
You are using VBA so familiar with Excel's objects. Your code does not correctly refer to the object you want to manipulate.


Go to the worksheet where the shape object is placed. Select the object and you will find its correct reference in the formula bar on the left side.
When I have to refer to a picture on a particular worksheet which is already there, I use following code.


ActiveSheet.Shapes("Picture 1").Select


However, the shapes (objects) added using VBA code during execution are given index numbers by Excel, and may be difficult to refer unless your code names them and than you refer them by code.


When I am adding a label on user form during execution, the code is:

Set objLbl = UserForm1.Controls.Add("Forms.Label.1")

objLbl.Name = "Label1"

UserForm1!Label1.Caption = "This is a test"


To refer to run time objects on UserForm, we have to use (!) separator.


The key point is correct object reference.


Hope this helps.
Mahess

Register to Reply
Guru

Join Date: Feb 2012
Posts: 595
#4
In reply to #2

Re: VBA (Excel 2007) Shape Handling

04/19/2013 10:31 AM

Selection.ShapeRange(1).TextFrame2.TextRange.Characters.Text

Selection. ◄ ???? i asume you have a region in worksheet that contains an illustrative shape(graphical) and some text in cells that describe the feature
if the layout is fixed then just and just it might be better to access the individual cells in this region by their relative adresses something as

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
MsgBox "The Cell(" & Target.Row & "," & Target.Column & ")" & vbLf & _
"Contains text [" & Worksheets("Sheet1").Cells(Target.Row, Target.Column).Text & "]"
End Sub

i really'm 2 lazy to test out your speciffic occasion

__________________
ci139
Register to Reply
Register to Reply 4 comments

Good Answers:

These comments received enough positive votes to make them "good answers".
Copy to Clipboard

Users who posted comments:

amitabha0107 (1); ci139 (1); Mahess Desai (1); terrapin (1)

Previous in Forum: Carpooling Phone App   Next in Forum: Schneider DDC Programming

Advertisement