vba 无法从 MS Project 设置 PageSetup.Orientation = xlLandscape
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1600895/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
can't set PageSetup.Orientation = xlLandscape from MS Project
提问by user191093
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
在 MS Project 2003 中使用 VBA 我创建了一个 Excel 工作表并将数据写入其中。之后我想更改我创建的工作表的 SetPrintArea 和 Orientation 所以我写了
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
它在 .Orientation 语句处崩溃。如果我注释掉它会在 .PrintArea 行崩溃。我的结论是它不能设置 .PageSetup 的任何属性
How can I specify the PrintArea ?
如何指定 PrintArea ?
回答by Hymanrnl
I installed BullZip PDF printer and after that .PageSetup.Orientation works. So it seems PageSetup NEEDS a printer to be installed.
我安装了 BullZip PDF 打印机,然后 .PageSetup.Orientation 工作。所以似乎 PageSetup 需要安装一台打印机。
回答by Christian Payne
You are doing the right thing.
你在做正确的事。
Why do you set txtPrintArea but then set the .PrintArea = xlSheet.UsedRange.Address ???
为什么你设置 txtPrintArea 然后设置 .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:
否则,您将需要发布更多代码作为示例。我根据您的问题创建了以下内容,它对我有用:
Set xlSheet = Sheet1
Set xlCol = Sheet1.Rows(1)
txtPrintArea = "A"
With xlSheet '// Defined being an Excel.Worksheet
xlSheet.UsedRange.Columns.EntireColumn.AutoFit
txtPrintArea = txtPrintArea & "$" & Trim(Str(xlCol.Row)) + ":b2" '// I created the range to print before
With .PageSetup
.Orientation = xlLandscape
.PrintArea = txtPrintArea '//xlSheet.UsedRange.Address
End With
End With