Преобразовать лист в PDF с отсутствующими изображениями - PullRequest
0 голосов
/ 29 мая 2020

Я использую этот код для преобразования листа в файл pdf. Я должен упомянуть, что мой лист Excel также содержит изображения в каждой ячейке столбца.

Sub SheetToPDF()

    Dim wsA As Worksheet
    Dim wbA As Workbook
    Dim strName As String
    Dim strPath As String
    Dim strFile As String
    Dim strPathFile As String
    Dim myFile As Variant
    Dim lOver As Long
    On Error GoTo errHandler

    Set wbA = ActiveWorkbook
    Set wsA = ActiveSheet

    'get active workbook folder, if saved
    strPath = wbA.Path
    If strPath = "" Then
      strPath = Application.DefaultFilePath
    End If
    strPath = strPath & "\"

    strName = "test"


    'create default name for savng file
    strFile = strName & ".pdf"
    strPathFile = strPath & strFile

    If bFileExists(strPathFile) Then
      lOver = MsgBox("Overwrite existing file?", _
        vbQuestion + vbYesNo, "File Exists")
      If lOver <> vbYes Then
        'user can enter name and
        ' select folder for file
        myFile = Application.GetSaveAsFilename _
          (InitialFileName:=strPathFile, _
              FileFilter:="PDF Files (*.pdf), *.pdf", _
              Title:="Select Folder and FileName to save")
        If myFile <> "False" Then
          strPathFile = myFile
        Else
          GoTo exitHandler
        End If
      End If
    End If

    'export to PDF in current folder
    wsA.ExportAsFixedFormat _
        Type:=xlTypePDF, _
        Filename:=strPathFile, _
        Quality:=xlQualityStandard, _
        IncludeDocProperties:=True, _
        IgnorePrintAreas:=False, _
        OpenAfterPublish:=False

    'confirmation message with file info
    MsgBox "Successfully created PDF file: " _
      & vbCrLf _
      & strPathFile

    exitHandler:
        Exit Sub
    errHandler:
        MsgBox "Could not create PDF file :("
        Resume exitHandler
    End Sub
    '=============================
    Function bFileExists(rsFullPath As String) As Boolean
      bFileExists = CBool(Len(Dir$(rsFullPath)) > 0)
    End Function

Проблема в том, что файл PDF отсутствует изображения (изображения были успешно скопированы только на последних 2 страницах) Есть ли какой-нибудь код, который поможет мне скопировать все изображения с листа Excel в файл PDF?

Большое спасибо!

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