Excel HPageBreaks无法正常工作,使用VBSCript [英] Excel HPageBreaks NOT working, using VBSCript

查看:133
本文介绍了Excel HPageBreaks无法正常工作,使用VBSCript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在第40行之后设置Excel分页符,但它出现在行号:45。我删除了所有默认分页符
以设置新的分页符。输出excel文件应为两页。




有人能告诉我我创造的错误。对你的帮助表示感谢。 (我试着从最近6个小时解决这个问题
但没有运气 
 )



此代码是我的任务的一部分,所以我在尝试这个而不改变co lumn width。

Option Explicit
Dim objExcel,objWorkbook,objSheet,objRange,intPageBreakRow,intRow,i

const xlPageBreakPreview  = &H2

Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
Set objWorkbook = objExcel.Workbooks.Add()
Set objSheet = objWorkbook.Worksheets(1)

Set objRange = objExcel.Range("B:F")
objRange.WrapText = TRUE

objSheet.Range("A:A").ColumnWidth = 1
objSheet.Range("B:B").ColumnWidth = 25
objSheet.Range("C:C").ColumnWidth = 25
objSheet.Range("D:D").ColumnWidth = 45
objSheet.Range("E:E").ColumnWidth = 14
objSheet.Range("F:F").ColumnWidth = 20

objSheet.DisplayAutomaticPageBreaks = False

With objSheet.PageSetup
 .Zoom = False
 .FitToPagesWide = 1
 .FitToPagesTall = 2
End With
objSheet.PageSetup.PrintArea = ""
objSheet.ResetAllPageBreaks  

intPageBreakRow=40
intRow=90

objExcel.Cells(1, 1).Value = "Page1 This is the text that we want to wrap in column A."
objExcel.Cells(2, 2).Value = "Page1 This is the text that we want to wrap in column B."
objExcel.Cells(3, 3).Value = "Page1 This is the text that we want to wrap in column C."
objExcel.Cells(5, 5).Value = "Page1 This is the text that we want to wrap in column E."
objExcel.Cells(6, 6).Value = "Page1 This is the text that we want to wrap in column F."

For i=2 To intPageBreakRow
    objExcel.Cells(i, 4).Value = "Page1 This is the text that we want to wrap in column D."
Next

objSheet.Range("F72").Value = "Page2 Some text aligned to the center"
objSheet.Range("F72").WrapText = True

For i=intPageBreakRow+1 To intRow
    objExcel.Cells(i, 4).Value = "Page2 This is the text that we want to wrap in column D."
Next

'objExcel.Range("A1: F"&intRow).Select  
objExcel.ActiveSheet.PageSetup.PrintArea="A1: F"&intRow
objSheet.ResetAllPageBreaks

'objExcel.Rows(intPageBreakRow+1).Select        
objSheet.HPageBreaks.Add objSheet.Rows(intPageBreakRow+1)

objExcel.ActiveWindow.View = xlPageBreakPreview                                     
objExcel.Rows.AutoFit




Krishnaprasad PK

Krishnaprasad P.K

推荐答案

部分

With objSheet.PageSetup

.Zoom = False

.FitToPagesWide = 1

.FitToPagesTall = 2

结束

With objSheet.PageSetup
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 2
End With

修复页面设置并使Excel忽略您的HPageBreak。如果您希望能够设置自己的分页符,则必须删除该部分代码。

fixes the page setup and makes Excel ignore your HPageBreak. If you want to be able to set your own page breaks, you must remove that part of the code.


这篇关于Excel HPageBreaks无法正常工作,使用VBSCript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆