I set this project aside for a while but it has come back into focus. The bold areas are where I need help (I can't seem to grasp the concept of arrays - or when I need to use them).
Here's what my code is so far:
[vba]
Sub MergeText()
On Error Resume Next
Dim shp As Shape
Dim sld As Slide
Dim myDocument As Slide
Dim mySlide As Integer
Dim tempText As String
Dim Response As Long
Dim rowsReply As Long
Dim colsReply As Long
Dim MyString As String
Dim txtArray As Variant
'go through everything in the current selection & get the text
mySlide = ActiveWindow.View.Slide.SlideIndex
With ActiveWindow.Selection
If .Type = ppSelectionShapes Then
For Each shp In .ShapeRange
If shp.HasTextFrame Then
'APPEND all text together into temp variable
tempText = tempText & shp.TextFrame.TextRange & Chr$(13)
End If
Next shp
End If
End With
'Ask if the selection used to be a table
'If NO, paste normally | If YES, paste the text in reverse order
Response = msgbox("Is the selection an ungrouped table?", 3, "Please answer...")
If Response = vbYes Then ' User chose Yes
MyString = "Yes"
'Ask how many rows and columns
colsReply = InputBox("How many columns?", "Columns", 4)
rowsReply = InputBox("How many rows?", "Rows", 4)
'dump the text into an array <--- Not sure how to do this
'(size of table based on rowsReply, colsReply)
Set myDocument = ActivePresentation.Slides(mySlide)
myDocument.Shapes.AddTable(rowsReply, colsReply).Name = "temptable" & mySlide
With myDocument.Shapes.Range("temptable" & mySlide)
'Paste the contents of the array in reverse order into the table <--- Not sure how to do this
End With
ElseIf Response = vbNo Then ' User chose No
MyString = "No"
'dump the value of the tempText on the slide
Set myDocument = ActivePresentation.Slides(mySlide)
myDocument.Shapes.AddTextbox(msoTextOrientationHorizontal, _
Left:=25.2, Top:=68.25, Width:=100, Height:=100).TextFrame.TextRange.Text = tempText
End If
End Sub
[/vba]
I was planning on doing this:
1) ask user if their selection is an ungrouped table
2a) if yes, find out how many columns and rows there used to be. Then I could take that information and dump the text from the selection into an array, and paste, in reverse order, into a table (size based on the cols/rows they specify).
2b) if no, paste into a normal textbox
Is my logic thorough enough or should I think it through more? (looks at Fumei)![]()