首页 > 解决方案 > 使用复选框从excel中获取多个pdf

问题描述

我的挑战是使用 checkbos 导出多个 excel 表。我已经完成了如下脚本,但它仅在选中一个复选框时才有效。行“阵列(tuloste)。选择两个复选框时,选择”是错误的。

Private Sub CommandButton1_Click()
Dim nimi
Dim tarjousnumero
Dim polku
Dim sivut As String
Dim Liite1
Dim Liite2
If CheckBox1.Value = True Then
Liite1 = "Palvelukuvaus"
Else
Liite1 = ""
End If
If CheckBox2.Value = True Then
Liite2 = "Etävalvonta"
Else
Liite2 = ""
End If
tuloste = Liite1 & Liite2
ActiveWorkbook.Save
Range("I2").Activate
tarjousnumero = ActiveCell
nimi = InputBox("Anna tiedoston nimi", "Tallenna pdf muodossa", "Tarjous " & tarjousnumero)
polku = ActiveWorkbook.Path
Sheets("Kaupallinen tarjous").Select
Sheets(Array(tuloste)).Select
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=polku & "\" & nimi & ".pdf", Quality:= _
xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _OpenAfterPublish:=False
Sheets("Kaupallinen tarjous").Select
UserForm2.Hide
End Sub

标签: excelvba

解决方案


对不起——下面少了外来词。我想制作一个 pdf_printout,它有一个固定的工作表(Kaupallinen tarjous)和我可以通过 chackboxes 选择的附件。此时最终的 pdf_printout 可以有 0 - 2 个附件。它可能会变成更多的复选框来选择,所以更多的动态代码也将不胜感激。但是现在我可以有 0 - 2 个附件。我通过使用 if 条件解决了打印输出具有“”值的问题,但仍然难以选择两个复选框。

Private Sub CommandButton1_Click()

Dim file
Dim offernumber
Dim path
Dim pages As String
Dim printout As String
Dim Appendix1 As String
Dim Appendix2 As String


If CheckBox1.Value = True Then
Appendix1 = "Our services"
Else
Appendix1 = ""
End If

If CheckBox2.Value = True Then
Appendix2 = "Remote control"
Else
Appendix2 = ""
End If

printout = Appendix1 & Appendix2

ActiveWorkbook.Save
Range("I2").Activate
offernumber = ActiveCell
file = InputBox("Anna tiedoston file", "Tallenna pdf muodossa", "Tarjous " & 
offernumber)
path = ActiveWorkbook.Path
Sheets("Kaupallinen tarjous").Select

if printout="" then
Sheets(“Kaupallinen tarjous”).Select
else
Sheets(array(“Kaupallinen tarjous”, printout)).Select

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=path & "\" & file & ".pdf", 
Quality:= _
    xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
    OpenAfterPublish:=False
Sheets("Kaupallinen tarjous").Select

UserForm2.Hide

End Sub

推荐阅读