Solved

Command button to open PDF set size and return error if not there

Posted on 2011-03-18
3
206 Views
Last Modified: 2012-06-22
Hi experts

I have the code below. It opens up a PDF in Acrobat.

I need to enhance this code by:
1) If the PDF doesn't exist it needs to return an error message to say "Can't find it". At the moment it just does nothing.
2) Is it possible to set the size of the PDF screen that appears? I'd like it to be half the screen size.

Option Explicit
Private Declare Function ShellExecute Lib "shell32" _
    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
    
Private Const SW_SHOWNORMAL As Long = 1
Private Const SW_SHOWMAXIMIZED As Long = 3
Private Const SW_SHOWDEFAULT As Long = 10
Private Const SE_ERR_NOASSOC As Long = 31

Private Sub CommandButton1_Click()
    Dim ThisDoc as Document
    Dim strOurRefGuide As String
    Set ThisDoc = ActiveDocument
    
    
    strOurRefGuide = ThisDoc.AttachedTemplate.Path & "\OurRefGuide.pdf"
    Call ShellExecute(0&, "open", strOurRefGuide, 0&, 0&, SW_SHOWNORMAL)



End Sub

Open in new window

0
Comment
Question by:Fi69
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 11

Accepted Solution

by:
Deepak Lakkad earned 500 total points
ID: 35171134
Hi

make following change in your code to check whether file is exist or not?

IF Dir$(strOurRefGuide) <> "" THEN  'Search for file
   Call ShellExecute(0&, "open", strOurRefGuide, 0&, 0&, SW_SHOWNORMAL)
ELSE
    MsgBox "Your Error message"
END IF

Open in new window


- Deepak Lakkad
0
 

Author Comment

by:Fi69
ID: 35173875
Thank for that. The error code for if the file doesn't exist is now working.

Do you know how to change the code to resize the PDF that apepars?
0
 
LVL 11

Expert Comment

by:Deepak Lakkad
ID: 35174041
have no more idea about it but,  following links can help a little

http://support.microsoft.com/kb/170918
http://support.microsoft.com/kb/238245

- Deepak Lakkad
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
This video shows and describes the main difference between both orientations in Microsoft Word. Viewers will understand when to use each orientation and how to get the most out of them.
Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question