|
2学分
程序主要是改变一个工作表的格式然后转换成pdf,蓝色部分是工作表格式,黄色部分是工作簿的设置和pdf打印,我想的是将pdf调整到一张表上而不是分开的。
图片是正确的格式和错误的格式。
运行时候第一次是正确的格式,之后就是错误的格式。
Sub daqinqin()
Dim n As Integer, i As Integer, fn
Dim r As Integer '行数
Dim filename, Wb As Workbook, sht As Worksheet
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.PrintCommunication = False
fn = Dir(ThisWorkbook.Path & "\病历*.xlsx")
Do While fn <> ""
myfile = ThisWorkbook.Path & "\" & fn
Set Wb = GetObject(myfile)
With Wb.Worksheets(1)
r = Wb.Worksheets(1).[A65536].End(3).Row
.Range("A1:BC" & r).HorizontalAlignment = xlCenter '水平居中
.Range("A1:BC" & r).VerticalAlignment = xlCenter '垂直居中
.Range("A1:BC" & r).WrapText = True '自动换行
.Columns("A:A").ColumnWidth = 24
.Columns("B:O").ColumnWidth = 13
.Columns("P:P").ColumnWidth = 100
.Columns("Q:T").ColumnWidth = 10
.Rows("1:" & r).RowHeight = 366
End With
'格式化
For Each sht In Wb.Worksheets
With sht.PageSetup
.Orientation = xlLandscape
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 1
End With
Next
Wb.ExportAsFixedFormat Type:=xlTypePDF, filename:= _
ThisWorkbook.Path & "\" & Left(fn, Len(myfile) - 5) & ".pdf"
Wb.Windows(fn).Visible = True
Wb.Close
Set Wb = Nothing
fn = Dir
Loop
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Application.PrintCommunication = True
End Sub
|
|