无法从 MS Project 设置 PageSetup.Orientation = xlLandscape
我在 MS Project 2003 中使用 VBA 创建一个 Excel 工作表并向其中写入数据。 之后,我想更改我创建的工作表的 SetPrintArea 和方向,所以我写了
with xlsheet '// Defined being an Excel.Worksheet
For i = 1 To .UsedRange.Columns.Count
.Columns(i).EntireColumn.AutoFit
Next i
txtPrintArea = txtPrintArea & "$" & xlCol.Row '// I created the range to print before
With .PageSetup
.Orientation = xlLandscape
.PrintArea = xlSheet.UsedRange.Address
End With
End With
It crashes at .Orientation 语句。 如果我注释掉它,它会在 .PrintArea 行崩溃。 我的结论是它无法设置 .PageSetup 的任何属性
如何指定 PrintArea ?
Using VBA in MS Project 2003 I create an Excel sheet and write data to it.
After that I want to change SetPrintArea and Orientation of the sheet I created so I wrote
with xlsheet '// Defined being an Excel.Worksheet
For i = 1 To .UsedRange.Columns.Count
.Columns(i).EntireColumn.AutoFit
Next i
txtPrintArea = txtPrintArea & "$" & xlCol.Row '// I created the range to print before
With .PageSetup
.Orientation = xlLandscape
.PrintArea = xlSheet.UsedRange.Address
End With
End With
It crashes at the .Orientation statement.
If I comment that out it crashes at the .PrintArea line.
My conclusion is it can't set any property of .PageSetup
How can I specify the PrintArea ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我安装了 BullZip PDF 打印机,之后 .PageSetup.Orientation 就可以工作了。
所以看来 PageSetup 需要安装打印机。
I installed BullZip PDF printer and after that .PageSetup.Orientation works.
So it seems PageSetup NEEDS a printer to be installed.
你正在做正确的事。
为什么你先设置txtPrintArea,然后再设置.PrintArea = xlSheet.UsedRange.Address ???
否则,您需要发布更多代码作为示例。我根据您的问题创建了以下内容,它对我有用:
You are doing the right thing.
Why do you set txtPrintArea but then set the .PrintArea = xlSheet.UsedRange.Address ???
Otherwise you'll need to post more code as an example. I created the following based on your question and it worked for me: