By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,635 Members | 913 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,635 IT Pros & Developers. It's quick & easy.

Opening a pdf in VBA, getting error 438

100+
P: 443
I've had code in my application for quite some time and now I'm getting error 438. This is the code
Expand|Select|Wrap|Line Numbers
  1. Print fHandleFile(app_path + "\shb.pdf", WIN_NORMAL)
this calls the FHandleFile function
Expand|Select|Wrap|Line Numbers
  1. Function fHandleFile(stFile As String, lShowHow As Long)
  2. Dim lRet As Long, varTaskID As Variant
  3. Dim stRet As String
  4. Dim Vresponse As String
  5.    'First try ShellExecute
  6.     lRet = apiShellExecute(hWndAccessApp, vbNullString, _
  7.             stFile, vbNullString, vbNullString, lShowHow)
  8.  
  9.     If lRet > ERROR_SUCCESS Then
  10.         stRet = vbNullString
  11.         lRet = -1
  12.     Else
  13.         Select Case lRet
  14.             Case ERROR_SUCCESS:
  15.                 varTaskID = Shell("rundll32.exe shell32.dll,OpenAs_RunDLL " _
  16.                         & stFile, WIN_NORMAL)
  17.                 lRet = (varTaskID <> 0)
  18.             Case ERROR_NO_ASSOC:
  19.                 'Try the OpenWith dialog
  20.                 varTaskID = Shell("rundll32.exe shell32.dll,OpenAs_RunDLL " _
  21.                         & stFile, WIN_NORMAL)
  22.                 lRet = (varTaskID <> 0)
  23.             Case ERROR_OUT_OF_MEM:
  24.                 stRet = "Error: Out of Memory/Resources. Couldn't Execute!"
  25.             Case ERROR_FILE_NOT_FOUND:
  26.                 stRet = "Error: Adobe acrobat reader not installed.  Couldn't Execute!"
  27.             Case ERROR_PATH_NOT_FOUND:
  28.                 stRet = "Error: Path not found. Couldn't Execute!"
  29.             Case ERROR_BAD_FORMAT:
  30.                 stRet = "Error:  Bad File Format. Couldn't Execute!"
  31.             Case Else:
  32.         End Select
  33.     End If
  34.     fHandleFile = lRet & IIf(stRet = "", vbNullString, ", " & stRet)
  35.     If fHandleFile = -1 Then
  36.  
  37.     Else
  38.         Vresponse = MsgBox(fHandleFile, vbOKOnly, "" & VMsgtitle & "")
  39.     End If
  40. End Function
  41.  
When it comes to the LRet code line is when I'm getting the 438 error "Object Doesn't support this property of method" however it does open the pdf.
I've tried using the Application.followhyperlink method but that give me a security error, that comes from Microsoft office "Opening shb.pdf Some files can contain viruses or otherwise e harmful to your computer. It is important to be certain that this file is from a trustworthy source. Would you like to open this file?"
I know this file if safe and is part of my application so I don't want that to show.
Either method is fine with me if I can figure out a way to do away with the error 438 or eliminate the security warming.
Any help is always appreciated.
Thanks
Oct 29 '17 #1

✓ answered by twinnyfo

Try replacing Print with Open

Share this Question
Share on Google+
5 Replies


twinnyfo
Expert Mod 2.5K+
P: 3,204
CD Tom,

I am not sure if you "need" to have such extensive code to print a PDF.

I use the following Code:

Expand|Select|Wrap|Line Numbers
  1.     strPrint = app_path + "\shb.pdf"
  2.     ShellExecute 0, "Print", strPrint, "", "", 0
Then, in a separate Module, declare the Function:

Expand|Select|Wrap|Line Numbers
  1. Public Declare Function ShellExecute _
  2.     Lib "shell32.dll" _
  3.     Alias "ShellExecuteA" ( _
  4.     ByVal hwnd As Long, _
  5.     ByVal lpOperation As String, _
  6.     ByVal lpFile As String, _
  7.     ByVal lpParameters As String, _
  8.     ByVal lpDirectory As String, _
  9.     ByVal nShowCmd As Long) _
  10.     As Long
It should work printing any file to your default printer. Unless I am missing something obvious, this should serve your purposes. Please clarify if it does not.

Hope this hepps!
Jan 2 '18 #2

100+
P: 443
Thanks for the reply. Now when I try your code I get "There was an error opening this document. The file is damaged and could not be repaired" If I just go to the document in explorer and double click it open just fine. Also I just want to display the document on the screen not print it.
What do you suggest.
Jan 4 '18 #3

twinnyfo
Expert Mod 2.5K+
P: 3,204
Try replacing Print with Open
Jan 5 '18 #4

100+
P: 443
Worked perfect thanks so much
Jan 5 '18 #5

twinnyfo
Expert Mod 2.5K+
P: 3,204
So glad I could be of some hepp!

Cheers!
Jan 5 '18 #6

Post your reply

Sign in to post your reply or Sign up for a free account.