我正在尝试创建一个代码以遍历用户窗体,以查看是否已选中复选框,然后创建工作表的PDF。 但是,在“ If ctl.controlFormat.Value = True Then”行中出现错误“对象不支持此属性或方法”。希望您能帮到我:)
Option Explicit
Sub Get_PDF_Click()
Dim ReportName As String
ReportName = ActiveSheet.Cells(4, 20).Value
Dim OutputPath As String
OutputPath = "T:\5. Fælles\Optima Lancering Version 1.0\6. Oversigtsark\KontoInvest\Historik\"
Dim YYMM As String
Dim Name_of_File As String
Dim Name As String
'Dim x1TypePDF As Variant
Dim cbox As CheckBox
Dim FormControlType As Variant
Dim ctl As Control
'Dim shp As Shape
YYMM = Format(WorksheetFunction.EoMonth(Now(), -1), "YYMM")
Name = "BankNordik_faktaark" & YYMM
Name_of_File = OutputPath & "BankNordik\" & Name
'------- LOOP THROUGH CHECKBOXES -------
For i = 0 To 6
For Each ctl In Me.Controls
'For Each ctl In PDFUserForm.Controls
If TypeName(ctl) = "CheckBox" Then
'If ctl.FormControlType = xlCheckBox Then
If ctl.ControlFormat.Value = True Then
For Each Ws In Worksheets
If Ws.Name = "Fakta " & Kunde_Array(i + 1, 1) Then
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
Name_of_File, Quality _
:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, OpenAfterPublish:=False
End If
Next Ws
End If
End If
Next ctl
Next i
End Sub