I'm trying to copy formatted text content from Excel to Powerpoint in VBA--preferably without copy-and-paste, as it just crashes every time I run it (even with multiple DoEvents to slow it down... there are hundreds of cells of heavily formatted text).
That's why I've been trying to get it to work by addressing the cells directly like in the code below.
For i = 1 To WS.Range("A65536").End(xlUp).Row
If WS.Cells(i, 1) > 0 Then
Set newSlide = ActivePresentation.Slides(1).Duplicate
newSlide.MoveTo (ActivePresentation.Slides.Count)
With newSlide.Shapes(1).TextFrame.TextRange
.Text = WS.Cells(i, 1).Value ' Inserts the (non-formatted) text from Excel. Have also tried WS.Cells(i, 1).Text
.Font.Name = WS.Cells(i, 1).Font.Name ' This works fine
.Font.Size = WS.Cells(i, 1).Font.Size ' This works fine too
' Neither of the below work because there is a mixture of font styled and colours within individual cells
.Font.FontStyle = WS.Cells(i, 1).Font.FontStyle ' Font Style (Regular, Bold, Italic, Bold Italic)
.Font.Color = WS.Cells(i, 1).Font.Color ' Font Color
End With
End If
Next
It works (very quickly) transferring the cell content, font name, and font size... but NOT for FontStyle (bold, italics, etc.) or FontColor because there is more than one style/color in individual cells.
Is there any way around this? I haven't the foggiest idea what the potential solution (if any) could be, so don't even know where to start looking. Even a push in the right direction would help enormously.
DisplayFormat
property of a range. eg..Font.Color = WS.Cells(i, 1).DisplayFormat.Font.Color
etc..... ( that is because the conditional formatting layers formats into a cell, and the top format is the one that you see.) ....... DisplayFormat is available starting Excel 2010 – jsotola.Font
with.DisplayFormat.Font
everywhere in your code ( on excel side of the assignment statement) – jsotola