内容导航:


一、excel宏编程如何对打印机进行设置


这个都可以用宏来设置的,比如:

LeftMargin 属性
以磅为单位返回或设置左边距的大小。Double 类型,可读写。

边距的设置和返回均以磅为单位。可使用 InchesToPoints 方法进行英寸到磅值的转换,也可使用 CentimetersToPoints 方法进行厘米到磅值的转换。

示例:
将 Sheet1 的左边距设为 1.5 英寸。

Worksheets("Sheet1").PageSetup.LeftMargin = Application.InchesToPoints(1.5)

将 Sheet1 的左页边距设为 2 厘米:
Worksheets("Sheet1").PageSetup.LeftMargin = Application.CentimetersToPoints(2)

显示 Sheet1 的左边距的当前设定值:
marginInches = Worksheets("Sheet1").PageSetup.LeftMargin / _
Application.InchesToPoints(1)
MsgBox "The current left margin is " & marginInches & " inches"

再示例
设置四个边界、页眉边界、页脚边界、纸张、打印缩放比例:

With ActiveSheet.PageSetup
.LeftMargin = Application.InchesToPoints(0.787)
.RightMargin = Application.InchesToPoints(1.181)
.TopMargin = Application.InchesToPoints(0.393)
.BottomMargin = Application.InchesToPoints(1.574)
.HeaderMargin = Application.InchesToPoints(0.511)
.FooterMargin = Application.InchesToPoints(0.905)
.PaperSize = xlPaperEnvelopeB5 '用B5纸
.Zoom = 95 '缩小到95%打印
End With

Good luck!


二、求教excel利用宏自动打印问题


插入模块
把如下代码复制进去。"sheet1"是工作表名,根据实际修改。复制好代码后在表中插入一个按钮,右键点击按钮---指定宏----选择这个打印宏。
Sub 打印()
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Call dy
End Sub
Sub dy()
Dim a%, b$, c$, abc$
a = Sheets("sheet1").Cells(3, 1).Value
b = Sheets("sheet1").Cells(5, 1).Value
If a < b Then
a = a + 1
Sheets("sheet1").Cells(3, 1).Value = a
Call 打印
End If
End Sub
Private Sub CommandButton1_Click()
Call 打印
End Sub