设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

返回列表 发新帖
查看: 2424|回复: 7
打印 上一主题 下一主题

[模块/函数] 请教~!可否用代码打开指定的PDF文件?

[复制链接]
1#
发表于 2016-11-17 10:48:30 | 显示全部楼层
国外网友的,前提是安装有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
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-5-21 21:18 , Processed in 0.091017 second(s), 23 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表