VBA Code for rotating TextBox

AlexMart

New Member
Joined
Mar 22, 2024
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hi everyone,
I'm new to VBA and would not mind some help from the community.
What I'm trying to do is a macro that reads an Excel file and create a circle and a text box for each and every line of my Excel sheet.
See code below
It works fine, but the only problem is that all the text boxes have the same orientation, equal to the final value of the Angle variable when the loop reaches the end.
What I'm trying to do is to get the orientation of text boxes matching all the values I have in the the second column of my excel file.
Your help will be much appreciated.

Sub Plot()

Dim i As Integer
Dim xlApp As Object
Dim xlWorkBook As Object
Dim xlSlide As Object
Dim Left As Double
Dim Top As Double
Dim Scale_factor As Double

Set xlApp = CreateObject("Excel.Application")

xlApp.Visible = True
Set xlWorkBook = xlApp.Workbooks.Open("C:\Users\Source.xlsx", True, False)

i = 2

While xlWorkBook.sheets("Sheet1").Cells(i, 1).Value <> 0
Left = xlWorkBook.sheets("Sheet1").Cells(i, 6).Value
Top = xlWorkBook.sheets("Sheet1").Cells(i, 7).Value
Name = xlWorkBook.sheets("Sheet1").Cells(i, 1).Value
Angle = xlWorkBook.sheets("Sheet1").Cells(i, 2).Value
ActivePresentation.Slides(1).Shapes.AddShape(msoShapeOval, 450 + Left, 250 + Top, 20 , 20).Select
ActivePresentation.Slides(1).Shapes.AddTextbox(msoTextOrientationHorizontal, 450 + Left, 250 + Top, 250, 25).TextFrame.TextRange.Text = Name
ActivePresentation.Slides(1).Shapes.Range.Rotation = Angle

i = i + 1
Wend

xlWorkBook.Close SaveChanges:=False
xlApp.Quit

End Sub
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
It is because this line
VBA Code:
ActivePresentation.Slides(1).Shapes.Range.Rotation = Angle
is rotating ALL shapes, not just the ones you want.

Change to something like:
VBA Code:
        With ActivePresentation.Slides(1).Shapes
            .AddShape(msoShapeOval, 450 + Left, 250 + Top, 20, 20).Select
            With .AddTextbox(msoTextOrientationHorizontal, 450 + Left, 250 + Top, 250, 25)
                .TextFrame.TextRange.Text = Name
                .Rotation = Angle
            End With
        End With
 
Upvote 1
It is because this line
VBA Code:
ActivePresentation.Slides(1).Shapes.Range.Rotation = Angle
is rotating ALL shapes, not just the ones you want.

Change to something like:
VBA Code:
        With ActivePresentation.Slides(1).Shapes
            .AddShape(msoShapeOval, 450 + Left, 250 + Top, 20, 20).Select
            With .AddTextbox(msoTextOrientationHorizontal, 450 + Left, 250 + Top, 250, 25)
                .TextFrame.TextRange.Text = Name
                .Rotation = Angle
            End With
        End With
@rlv01 You're a star! It works!
Thanks a lot.
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,193
Members
452,616
Latest member
intern444

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