将excel行转换为pdf循环

时间:2017-09-26 09:57:42

标签: excel pdf

我想知道您是否可以帮我修改此代码...它使用数据集查找指标行以匹配字段并完成指标定义的表单。通过将列修改为yesno可以完成此操作一次或多次。

它目前将每个指标导出到单独的PDF - 我希望选择的指标范围合并为单个pdf - 这是否可以在出口中实现?对于union打印范围可能是这样的吗?

或者,如果可能将每个输出作为图像粘贴到空工作表,然后导出为pdf?

Sub print_selected_rows(inputData As Range, outputData As Range)

Dim data_columns, data_rows, filter_column, i, j
Dim ThisFile As Variant

data_rows = getArrayRows(inputData)
data_columns = getArrayColumns(inputData)

For i = 1 To data_columns
If (inputData.Cells(1, i).Value = "Select for report") Then
    filter_column = i
    Exit For
End If
Next

Sheets("Output").Visible = True
Sheets("Output").Select

For i = 1 To data_rows
If ((inputData.Cells(i, filter_column).Value = "yes") Or (inputData.Cells  (i, filter_column).Value = "Yes") _
    Or (inputData.Cells(i, filter_column).Value = "Y") Or (inputData.Cells(i, filter_column).Value = "y")) Then
'copy row data to output sheet
    For j = 1 To data_columns
        outputData.Cells(j, 3).Value = inputData.Cells(i, j).Value
    Next

    ThisFile = Application.GetSaveAsFilename( _
        "abc" & " " & _
        Range("selected_ID").Value, "PDF Files (*.pdf), *.pdf")
    If VarType(ThisFile) = vbString Then
        ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=ThisFile, _
        Quality:=xlQualityStandard, IncludeDocProperties:=True, _
        IgnorePrintAreas:=False, OpenAfterPublish:=False
    End If
End If
Next

Sheets("Introduction").Visible = True
Sheets("Introduction").Select
Sheets("Output").Visible = False

End Sub

1 个答案:

答案 0 :(得分:0)

我设法通过使用以下代码将图像复制并粘贴到新工作表来解决此问题:

Sub print_selected_rows(inputData As Range, outputData As Range)

Dim data_columns, data_rows, filter_column, i, j, k
Dim ThisFile As Variant

k = 0

data_rows = getArrayRows(inputData)
data_columns = getArrayColumns(inputData)

For i = 1 To data_columns
If (inputData.Cells(1, i).Value = "Select for report") Then
    filter_column = i
    Exit For
End If
Next

Sheets("Output").Visible = True
Sheets("Output").Select

For i = 1 To data_rows
If ((inputData.Cells(i, filter_column).Value = "yes") Or (inputData.Cells (i, filter_column).Value = "Yes") _
    Or (inputData.Cells(i, filter_column).Value = "Y") Or (inputData.Cells(i, filter_column).Value = "y")) Then
'copy row data to output sheet
    For j = 1 To data_columns
        outputData.Cells(j, 3).Value = inputData.Cells(i, j).Value
     Next
      With ThisFile
        Sheets("Output").Range("A1:J55").CopyPicture xlScreen, xlBitmap
        Worksheets("Sheet1").Paste _
        Worksheets("Sheet1").Range("A1").Offset(k, 0)
        k = k + 56
      End With
End If
Next

Sheets("Introduction").Visible = True
Sheets("Introduction").Select
Sheets("Output").Visible = False
Sheets("Sheet1").Visible = False

End Sub