Solved

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

Posted on 2011-03-18
3
202 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
  • 2
3 Comments
 
LVL 11

Accepted Solution

by:
Deepak Lakkad earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

I would like to show you some basics you can do with Mailings in MS Word. It´s quite handy feature you can use for creating envelopes, labels, personalized letters etc. First question could be what is this feature good for? Mailing can really he…
A few years ago I was very much a beginner at VBA, and that very much remains the case today.  I'll do my best to explain things as I go in the hope that other beginners can follow.  If you just want to check out a tool that creates a Select Case fu…
This video teaches the viewer how to align pictures around text while keeping the text properly aligned in the document.
The viewer will learn how to make their project stand out over others by learning how to change colors and shapes, add spaces, change directions, and add bullets to their charts.

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now