View Full Version : PasteSpecial+Bold+Center+Font Size
demolay
12-05-2008, 06:14 AM
Hello,
Initially, I was having hard time with finding a macro code to do paste special from excel to ppt. Simply, I copy some cells in excel, go to ppt and select some cells/rows in a table, paste special as unformatted text, then make them bold, centered and font size=12.
I found this code to be useful in making paste special part:
PowerPoint.Application.ActiveWindow.View.pastespecial (ppPasteText)
But I cannot make my text bold, centered and font size. My text is in a table. I dont want to make the whole table bold. I just want to make copy-pasted part bold. And there is no fixed part of table that I do paste. Sometimes it is 2nd row, sometimes 1st column, etc.
I dont know almost anything about VBA, I just try to create macros by manipulating existing knowledge on web. It works great for excel, but ppt macros are really hard for me. So, if you dont get my question, I can further inform you.
Thanks in advance.
Zack Barresse
12-09-2008, 03:08 PM
Hi there, welcome to the board!
You could use something like this to format your table...
Sub FormatSelectedTable()
Dim iRow As Long, iCol As Long
On Error GoTo ErrorHandle
With ActiveWindow.Selection.ShapeRange(1)
If .Type <> msoTable Then GoTo ErrorHandle
.Table.Cell(2, 3).Shape.TextFrame.TextRange.Font.Bold = msoTrue
.Table.Cell(2, 3).Shape.TextFrame.TextRange.ParagraphFormat.Alignment = ppAlignCenter
.Table.Cell(2, 3).Shape.TextFrame.TextRange.Font.Size = 12
End With
Exit Sub
ErrorHandle:
MsgBox "You do not have a table selected."
End Sub
Other than that I'm not sure how to figure out what the part of the table is you pasted. The active cell perhaps?
HTH
demolay
12-16-2008, 01:26 AM
Yes, I need to paste to active cells.
Simply I do the following manually: Copy some cells from excel, go to ppt, select some cells in a table, then paste special as unformatted text, do bold, do font 12, do align center.
I need to have macro that do the part starting from paste special. So, I will copy some cells from excel, go to ppt, select some cells in a table, and click macro.
Zack Barresse
12-17-2008, 04:08 PM
No, but if it's selected, you should be able to do that...
Sub FormatSelectedTable()
Dim iRow As Long, iCol As Long, iC As Long, iR As Long
On Error GoTo ErrorHandle
With ActiveWindow.Selection.ShapeRange(1)
If .Type <> msoTable Then GoTo ErrorHandle
For iR = 1 To .Table.Rows.Count
For iC = 1 To .Table.Columns.Count
If .Table.Cell(iR, iC).Selected = True Then
.Table.Cell(iR, iC).Shape.TextFrame.TextRange.Font.Bold = msoTrue
.Table.Cell(iR, iC).Shape.TextFrame.TextRange.ParagraphFormat.Alignment = ppAlignCenter
.Table.Cell(iR, iC).Shape.TextFrame.TextRange.Font.Size = 12
Exit For
End If
Next iC
Next iR
End With
Exit Sub
ErrorHandle:
MsgBox "You do not have a table selected."
End Sub
Haven't tested this new code, unable to at the moment.
demolay
12-18-2008, 12:51 AM
I select cells, run macro, but nothing happens :(
No error, no change in text...
John Wilson
12-18-2008, 01:35 AM
I select cells, run macro, but nothing happens :(
No error, no change in text...
Maybe this ammendment?
Sub FormatSelectedTable()
Dim iC As Integer, iR As Integer
On Error GoTo ErrorHandle
With ActiveWindow.Selection.ShapeRange(1)
If .Type <> msoTable Then GoTo ErrorHandle
For iR = 1 To .Table.Rows.Count
For iC = 1 To .Table.Columns.Count
If .Table.Cell(iR, iC).Selected Then
.Table.Cell(iR, iC).Shape.TextFrame.TextRange.Font.Bold = msoTrue
.Table.Cell(iR, iC).Shape.TextFrame.TextRange.ParagraphFormat.Alignment = ppAlignCenter
.Table.Cell(iR, iC).Shape.TextFrame.TextRange.Font.Size = 12
End If
Next iC
Next iR
End With
Exit Sub
ErrorHandle:
MsgBox "You do not have a table selected."
End Sub
demolay
12-18-2008, 01:40 AM
Wow, that works!
You cannot imagine how much time this macro going to save.
Thanks a lot.
John Wilson
12-23-2008, 08:50 AM
Glad it helped! Post money to Zack and he can buy me an Alaskan Ale at the MVP Summit in March! ;o)
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.