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
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