[英]what is wrong with this line of vba code for Excel Print
I have a combobox with list of page size in excel.我有一个 combobox 与 excel 中的页面大小列表。 i want to change page sizes with combobox selection change.我想通过 combobox 选择更改来更改页面大小。
Following is not working以下不起作用
Public Sub UpdateSize()
Dim Papersizetext As String
Papersizetext = "xlPaper" & Worksheets("Static").Range("B7").value 'A4 is the value in cell B7
shgenerate.PageSetup.PaperSize = Papersizetext 'not working
shgenerate.PageSetup.PaperSize = "xlPaper" & Combobox1.value 'this also not working
shgenerate.PageSetup.PaperSize = xlPaperA4 'is working - i want above to work.
'shgenerate is sheet name
End sub
You could whip up your own function to parse the input and return the correct enum member:您可以创建自己的 function 来解析输入并返回正确的枚举成员:
Private Function PaperSize(ByVal rawSize As String) As Long
Select Case rawSize
Case "A4"
PaperSize = xlPaperA4
Case "A3"
PaperSize = xlPaperA3
Case "A5"
PaperSize = xlPaperA5
Case Else
PaperSize = xlPaperUser ' or some other default
End Select
End Function
For more complex paper sizes, such as "Letter 8.5"x11" 22x28cm"
or "Legal 8.5"x14" 22x36cm"
, you could possibly use InStr
to test of the existence of "Letter" and "Legal" to return xlPaperLetter
and xlPaperLegal
.对于更复杂的纸张尺寸,例如"Letter 8.5"x11" 22x28cm"
或"Legal 8.5"x14" 22x36cm"
,您可以使用InStr
来测试 "Letter" 和 "Legal" 的存在以返回xlPaperLetter
和xlPaperLegal
。
Regex might be another approach to parse out the dimensions.正则表达式可能是解析维度的另一种方法。
Without more detail though, it's hard to give a satisfactory answer, as this question is actually quite a broad topic.但是,如果没有更多细节,很难给出令人满意的答案,因为这个问题实际上是一个相当广泛的话题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.