Office中国论坛/Access中国论坛

标题: 请教~!可否用代码打开指定的PDF文件? [打印本页]

作者: sxgaobo    时间: 2016-11-14 18:05
标题: 请教~!可否用代码打开指定的PDF文件?
可否用代码打开指定的PDF文件?并显示指定的页!
作者: tmtony    时间: 2016-11-14 18:18
打开 可以的。HyperFollow
但显示指定页 没有试过,估计要找PDF控件的接口
作者: tmtony    时间: 2016-11-14 18:27
QQ群网友回复
ACCESS(342366170)  18:19:45
Public Declare 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
'ShellExecute函数二次封装,以简化使用,输入参数File可以是文件名,网页地址或命令行
Public Function ShellEx(File As String)
    ShellExecute hWndAccessApp, "Open", File, 0, 0, 1
End Function
ACCESS(342366170)  18:20:50
        ShellEx (“文件全名”)
可打开任何文件
ACCESS(342366170)  18:22:42
例: ShellEx (“d:\user\aaa.pdf”)
例: ShellEx (“d:\user\aaa.doc”)
例: ShellEx (“d:\user\aaa.xls”)
例: ShellEx (“d:\user\aaa.jpg”)



tmtony小辣椒(18449932)  18:26:19
@ACCESS
zpy2(1928323988)  18:26:41

tmtony小辣椒(18449932)  18:27:20
Access下也可用
Application.FollowHyperlink  “d:\user\aaa.pdf”

作者: sxgaobo    时间: 2016-11-15 09:09
谢谢版主的关注!现在最迫切需要的是‘显示指定的页’啊
作者: tmtony    时间: 2016-11-15 12:45
因为PDF 是用第三方软件打开的。除非用PDF插件,否则应该控制不了的
作者: sxgaobo    时间: 2016-11-15 14:33
tmtony 发表于 2016-11-15 12:45
因为PDF 是用第三方软件打开的。除非用PDF插件,否则应该控制不了的

明白,只是不死心,有这方面的插件吗?
作者: Benjamin_luk    时间: 2016-11-17 10:48
国外网友的,前提是安装有Acrobat:
用IE也可显示PDF,但不确定能否显示指定页
Option Explicit
Option Private Module
Sub OpenPDFPageView()   
    'By Christos Samaras
    'http://www.myengineeringworld.net
   
    'In order to use the macro you must enable the Acrobat library from VBA editor:
    'Go to Tools -> References -> Adobe Acrobat xx.0 Type Library, where xx depends
    'on your Acrobat Professional version (i.e. 9.0 or 10.0) you have installed to your PC.
   
    'Alternatively you can find it Tools -> References -> Browse and check for the path
    'C:\Program Files\Adobe\Acrobat xx.0\Acrobat\acrobat.tlb
    'where xx is your Acrobat version (i.e. 9.0 or 10.0 etc.).
   
    Dim PDFApp As AcroApp
    Dim PDFDoc As AcroAVDoc
    Dim PDFPageView As AcroAvPageView
    Dim PDFPath As String
    Dim DisplayPage As Integer
   
    'Change this to your own complete PDF path
    'Full path example
    'PDFPath = "C:\Program Files\Autodesk\ACADM 2010\Setup\en-US\SetupRes\Docs\Acad_Mech_2010_UserGuide.pdf"
    'For Word
    'PDFPath = ThisDocument.Path & "\" & "PDF Sample.pdf"
    'For Power Point
    'PDFPath = ActivePresentation.Path & "\" & "PDF Sample.pdf"
    'For Excel
    PDFPath = ThisWorkbook.Path & "\" & "PDF Sample.pdf"
   
    'Set the page you want to be displayed
    DisplayPage = 3
   
    'Initialize Acrobat by creating App object
    Set PDFApp = CreateObject("AcroExch.App")
   
    'Set AVDoc object
    Set PDFDoc = CreateObject("AcroExch.AVDoc")
   
    'Open the PDF
    If PDFDoc.Open(PDFPath, "") = True Then
        PDFDoc.BringToFront
        
        'Maximize the document
        Call PDFDoc.Maximize(True)
        
        Set PDFPageView = PDFDoc.GetAVPageView()
        
        'Go to the desired page
        'The first page is 0
        Call PDFPageView.GoTo(DisplayPage - 1)
        
        '-------------
        'ZOOM options
        '-------------
        '0 = AVZoomNoVary
        '1 = AVZoomFitPage
        '2 = AVZoomFitWidth
        '3 = AVZoomFitHeight
        '4 = AVZoomFitVisibleWidth
        '5 = AVZoomPreferred
        
        'Set the page view of the pdf
        Call PDFPageView.ZoomTo(2, 50)
   
    End If

    Set PDFApp = Nothing
    Set PDFDoc = Nothing
   
    On Error Resume Next
   
    'Show the adobe application
    PDFApp.Show
   
    'Set the focus to adobe acrobat pro
    AppActivate "Adobe Acrobat Pro"
        
End Sub
作者: tmtony    时间: 2016-11-19 10:12
Benjamin_luk 发表于 2016-11-17 10:48
国外网友的,前提是安装有Acrobat:
用IE也可显示PDF,但不确定能否显示指定页
Option Explicit

老友,好久不见了,回归论坛了:)




欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/) Powered by Discuz! X3.3