Link to home
Start Free TrialLog in
Avatar of Fi69
Fi69

asked on

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

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

ASKER CERTIFIED SOLUTION
Avatar of Deepak Lakkad
Deepak Lakkad
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Fi69
Fi69

ASKER

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?
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