can't set PageSetup.Orientation = xlLandscape from MS Project

拟墨画扇 提交于 2019-12-12 23:03:27

问题


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 ?


回答1:


I installed BullZip PDF printer and after that .PageSetup.Orientation works. So it seems PageSetup NEEDS a printer to be installed.




回答2:


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


来源:https://stackoverflow.com/questions/1600895/cant-set-pagesetup-orientation-xllandscape-from-ms-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!