作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个主表单(我想我可以这样称呼它),它将 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
谢谢大家的帮助!
关于excel - 复选框仅在主宏运行后运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67419286/
我是一名优秀的程序员,十分优秀!