复选框,仅在运行主宏后运行

  • 本文关键字:运行 复选框 excel vba
  • 更新时间 :
  • 英文 :


我有一个主表单(我想我可以这么称呼它(,它将Excel表导出到PDF。我想有一个复选框,允许用户在运行后打开PDF文件,如果它被选中的话。此时,当单击复选框时,它会尝试运行复选框宏,但如果未选中,则会返回错误。这是代码:

Sub CheckBox5_Click()
Dim ws As Worksheet
Dim chckBox As CheckBox
Set chckBox = Sheets("CompileSheet").CheckBoxes("CheckBox5")
Set ws = ThisWorkbook.Sheets("Sheet2")
If chckBox.Value = 1 Then
ws.ExportAsFixedFormat Type:=xlTypePDF, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
OpenAfterPublish:=True
Else
ws.ExportAsFixedFormat Type:=xlTypePDF, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
OpenAfterPublish:=False
End If
End Sub

不要犹豫,要求澄清。谢谢

我搞定了!

我不得不将复选框宏留空(我不知道你能(,并找出了如何找到复选框的名称,并且在创建工作表后的以下代码对我有效:

If xlBook.Sheets("CompileSheet").Shapes("Check Box 5").OLEFormat.Object.Value = 1 Then
ws.ExportAsFixedFormat Type:=xlTypePDF, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
OpenAfterPublish:=True
Else
ws.ExportAsFixedFormat Type:=xlTypePDF, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
OpenAfterPublish:=False
End If

感谢大家的帮助!

最新更新