无法从 MS Project 设置 PageSetup.Orientation = xlLandscape

发布于 2024-08-09 01:03:37 字数 633 浏览 11 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

紫﹏色ふ单纯 2024-08-16 01:03:37

我安装了 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.

冷…雨湿花 2024-08-16 01:03:37

你正在做正确的事。

为什么你先设置txtPrintArea,然后再设置.PrintArea = xlSheet.UsedRange.Address ???

否则,您需要发布更多代码作为示例。我根据您的问题创建了以下内容,它对我有用:

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

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:

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文