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