Using VBA in MS Project 2003 I create an Excel sh开发者_如何转开发eet 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 ?
I installed BullZip PDF printer and after that .PageSetup.Orientation works. So it seems PageSetup NEEDS a printer to be installed.
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
精彩评论