VBA Вставка HTML в PowerPoint с сохранением исходного форматирования - PullRequest
0 голосов
/ 22 апреля 2020

У меня есть диапазон текста, и в ячейках я изменяю часть текста ячейки на другие цвета через VBA. Далее я хочу скопировать и вставить этот диапазон в PowerPoint, сохраняя цвета. Однако, когда я вставляю его в PowerPoint как HTML или просто по умолчанию, он не сохраняет изменения цвета. Обратите внимание, что решение заключается не в том, чтобы копировать как рисунок, так как мне нужно иметь возможность редактировать текст в PowerPoint.

Ниже текста в Excel (с цветами) и в результате PowerPoint (без цветов)

Excel (with colors) PowerPoint (colors not showing)

и фрагмент кода

Sub CopyPaste()
Dim PowerPointApp As PowerPoint.Application
Dim myPresentation As PowerPoint.Presentation
Dim mySlide As PowerPoint.Slide
Dim myShapeRange As PowerPoint.Shape
Dim rngArr As Variant
Dim InfoboksRng As String
Dim i as integer

InfoboksRng = "AF67:AI77"
rngArr = Array(InfoboksRng) ' Snippet of array
For i = LBound(rngArr) To UBound(rngArr)
          ThisWorkbook.ActiveSheet.Range(rngArr(i)).Copy
          On Error Resume Next
              Set PowerPointApp = GetObject(class:="PowerPoint.Application")
              Err.Clear
              If PowerPointApp Is Nothing Then Set PowerPointApp = CreateObject(class:="PowerPoint.Application")
              If Err.Number = 429 Then
                MsgBox "PowerPoint could not be found, aborting."
                Exit Sub
              End If
          On Error GoTo 0


        ''Make PowerPoint Visible and Active
          PowerPointApp.Visible = True
          PowerPointApp.Activate
        '
        ''Create a New Presentation
            Set myPresentation = PowerPointApp.ActivePresentation
            sld = PowerPointApp.ActiveWindow.View.Slide.SlideIndex

        ''Add a slide to the Presentation
          Set mySlide = myPresentation.Slides(sld)

        'Paste to PowerPoint and position


            'Set position:
         Select Case i ' Snippet
            Case Is = 0 ' Infoboks
             mySlide.Shapes.PasteSpecial ppPasteHTML, msoFalse ' Paste as metafile not the solution

        End Select

        'Clear The Clipboard
          Application.CutCopyMode = False
Next i

End sub
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...