0
我试图将格式化的文本内容从Excel复制到Powerpoint的VBA中 - 最好没有复制和粘贴,因为它只是崩溃每一个当我运行它(即使有多个DoEvents来减慢速度...有数百个格式严格的文本)。VBA从Excel复制到PowerPoint(不是“复制和粘贴”)
这就是为什么我一直试图通过像下面的代码中直接寻址单元格来使它工作。
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
它的工作原理(非常快),使单元的内容,字体名称和字体大小...但不使用FontStyle(粗体,斜体等)或FONTCOLOR因为有多个样式/颜色在个别细胞中。
有没有办法解决这个问题?我不知道潜在的解决方案(如果有的话)可能是什么,所以甚至不知道从哪里开始寻找。即使向正确的方向推动也会有很大的帮助。
您可能会将条件格式应用于某些工作表单元格。如果你这样做,你必须使用范围的'DisplayFormat'属性。例如。 '.Font.Color = WS.Cells(i,1).DisplayFormat.Font.Color'等.....(这是因为条件格式化图层格式化为一个单元格,顶层格式是您看到的格式)....... DisplayFormat开始Excel 2010 – jsotola
只需用代码中的'.DisplayFormat.Font'替换'.Font'(在赋值语句的Excel侧) – jsotola
感谢您的帮助jsotola。 .DisplayFormat似乎工作正常,单元格中的所有文本都是粗体......或斜体......或单一颜色。 但是,在我的电子表格中,每个单元格都有这些的混合。例如,在一些单元格中,有一些单词用粗体表示,其他单元格不用粗体...都在同一单元格中。 在其他单元格中,有些单词是黑色的,有些单词是红色的......再次,都在同一个单元格中。 (使用.DisplayFormat与这种混合的样式/颜色导致错误:“”运行时错误438。对象没有'这是否有道理?我认为也许我的问题没有使这部分非常明确。) – ThomasKa