设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

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

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

[复制链接]
跳转到指定楼层
1#
发表于 2016-11-14 18:05:39 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
可否用代码打开指定的PDF文件?并显示指定的页!
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 分享淘帖 订阅订阅

点击这里给我发消息

2#
发表于 2016-11-14 18:18:59 | 只看该作者
打开 可以的。HyperFollow
但显示指定页 没有试过,估计要找PDF控件的接口

点击这里给我发消息

3#
发表于 2016-11-14 18:27:50 | 只看该作者
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”
4#
 楼主| 发表于 2016-11-15 09:09:56 | 只看该作者
谢谢版主的关注!现在最迫切需要的是‘显示指定的页’啊

点击这里给我发消息

5#
发表于 2016-11-15 12:45:44 | 只看该作者
因为PDF 是用第三方软件打开的。除非用PDF插件,否则应该控制不了的
6#
 楼主| 发表于 2016-11-15 14:33:12 | 只看该作者
tmtony 发表于 2016-11-15 12:45
因为PDF 是用第三方软件打开的。除非用PDF插件,否则应该控制不了的

明白,只是不死心,有这方面的插件吗?
7#
发表于 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

点击这里给我发消息

8#
发表于 2016-11-19 10:12:32 | 只看该作者
Benjamin_luk 发表于 2016-11-17 10:48
国外网友的,前提是安装有Acrobat:
用IE也可显示PDF,但不确定能否显示指定页
Option Explicit

老友,好久不见了,回归论坛了:)
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-5-1 14:39 , Processed in 0.124303 second(s), 31 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

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