|
本帖最后由 jerryfzwyj 于 2018-8-9 16:22 编辑
要实现功能如下
excel打开pdf文档,然后将pdf截屏,并贴到excel中。然后对照片进行部分裁减并保存
目前代码如下,在pdf打开后截屏不知道有没有发生,但是在excel中看不见图片,最终结果图片生产了,但是只是一个excel的单元格
请大神帮忙看下代码有什么问题
Option Explicit
Private Declare Sub keybd_event Lib "User32" _
(ByVal bVk As Byte, _
ByVal bScan As Byte, _
ByVal dwFlags As Long, _
ByVal dwExtraInfo As Long)
Private Declare Function CloseClipboard Lib "User32" () As Long
Private Declare Function GetClipboardData Lib "User32" _
(ByVal uFormat As Long) As Long
Private Declare PtrSafe Function ShellExecute Lib "shell32.dll" _
Alias "ShellExecuteA" (ByVal hWnd As Long, _
ByVal lpOperation As String, ByVal lpFile As String, _
ByVal lpParameters As String, ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long
Sub prtsc()
Dim mypath, myname, Filename
Application.EnableEvents = False
On Error Resume Next
Shapes.SelectAll
Selection.ShapeRange.Delete
Sheet1.Range("a1").Select
Application.Wait (Now + TimeValue("00:00:01"))
mypath = "XXX\Source\"
myname = Sheet1.Cells(1, 23).Value & ".pdf"
ShellExecute Application.hWnd, "open", mypath & myname, "", "", 0
Application.Wait (Now + TimeValue("00:00:07"))
keybd_event 44, 0&, 0&, 0&
DoEvents
Application.Wait (Now + TimeValue("00:00:01"))
Shell "taskkill /f /im AcroRd32.exe"
ActiveSheet.Range("a1").Paste
Dim i, H, W, Tpath
Tpath = "XXX\Result\"
For i = 1 To 2
If i = 1 Then
With Selection.ShapeRange
.PictureFormat.CropTop = 400
.PictureFormat.CropLeft = 300
.PictureFormat.CropBottom = 90
.PictureFormat.CropRight = 740
.IncrementLeft -300
.IncrementTop -380
.IncrementRotation 0
End With
Else
With Selection.ShapeRange
.PictureFormat.CropTop = 400
.PictureFormat.CropLeft = 710
.PictureFormat.CropBottom = 140
.PictureFormat.CropRight = 310
.IncrementLeft -710
.IncrementTop -380
.IncrementRotation 0
End With
End If
Sheet1.Shapes(1).Select
H = Selection.Height
W = Selection.Width
Selection.ShapeRange.ScaleHeight 1#, msoTrue, msoScaleFromTopLeft
Selection.ShapeRange.ScaleWidth 1#, msoTrue, msoScaleFromTopLeft
Selection.CopyPicture
With ActiveSheet.ChartObjects.Add(0, 0, Selection.Width, Selection.Height).Chart
.Paste
.Export Tpath & "\" & Sheets(1).Cells(1, 22 + i) & ".png"
.Parent.Delete
End With
Next
End Sub
|
|