|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
代码如下。。。
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address <> "$M$11" Then Exit Sub
Set wb = ThisWorkbook
p = wb.Path & "\图片\"
s = Target.Value
Me.[j2] = s
Me.Pictures.Delete
f = Dir(p & "*.jpg")
Do While f <> ""
If InStr(f, "第" & s & "期") Then
For i = 1 To 2
If InStr(f, "(" & i & ")") Then
Me.Shapes.AddPicture _
p & f, 0, 1, 3 + (i - 1) * 223.75, 536.25, 216, 144
End If
Next
End If
f = Dir
Loop
Me.PageSetup.PrintArea = "a1:f16"
Application.Dialogs(9).Show '此为选择打印机,不要可以注释掉
Me.PrintPreview '此为打印预览,需要打印改为printout即可
f = wb.Path & "\第" & s & "期" '& ".pdf" '新加的两行输出为PDF文件,在同一个文件夹下,名称为第?期
Me.ExportAsFixedFormat Type:=xlTypePDF, Filename:=f
End Sub
Sub 打印()
ActiveSheet.PageSetup.PrintArea = "a1:f16"
ActiveSheet.PrintOut
End Sub
|
|