TheSwamp

Code Red => VB(A) => Topic started by: krampaul82 on June 07, 2010, 02:17:20 PM

Title: VBa
Post by: krampaul82 on June 07, 2010, 02:17:20 PM
How do I open a .pdf file from a Visual Basic Program?
any help appreciated...
Title: Re: VBa
Post by: Keith™ on June 07, 2010, 03:18:34 PM
Open it as open adobe to view it or open it as open it in VBA to do something with it?

Prior is something like this:

Code: [Select]
Option Explicit

Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpszOp As String, ByVal lpszFile As String, ByVal lpszParams As String, ByVal lpszDir As String, ByVal FsShowCmd As Long) As Long

Public Function OpenFile(ByVal FileName As String) As Long
   OpenFile = ShellExecute(0, "Open", FileName, "", "C:\", 1)
End Function

latter isn't gonna happen without some knowledge of the PDF structure and/or a type library and/or a class for handling PDF files.
Title: Re: VBa
Post by: krampaul82 on June 07, 2010, 03:56:05 PM
I would like to press a command button and have it open an adobe pdf file for printing
Title: Re: VBa
Post by: Keith™ on June 07, 2010, 04:01:13 PM
well, that will do it, just pass the file name to the function and it will open the PDF in adobe
Title: Re: VBa
Post by: krampaul82 on June 07, 2010, 04:42:07 PM
using your example above how would i pass the filename to this function?
(at your convienence.....)
Title: Re: VBa
Post by: Keith™ on June 07, 2010, 04:48:33 PM
Code: [Select]
OpenFile "filenamegoeshere"

That simple
Title: Re: VBa
Post by: krampaul82 on June 07, 2010, 04:57:56 PM
Option Explicit

Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpszOp As String, ByVal lpszFile As String, ByVal lpszParams As String, ByVal lpszDir As String, ByVal FsShowCmd As Long) As Long

Public Function OpenFile(ByVal FileName As String) As Long

   OpenFile = ShellExecute(0, "Open", FileName, "", "C:\ALL_pdf_Cut_Sheets\Actuators\", 1)
End Function

like this?
sub file_get
OpenFile "ms8105a1008"
End Sub
Title: Re: VBa
Post by: Keith™ on June 07, 2010, 05:41:56 PM
that should do it, but you might need to include the path to the file as well. All I can suggest it to try it
Title: Re: VBa
Post by: krampaul82 on June 08, 2010, 10:14:26 AM
No Dice... :|

Option Explicit

Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpszOp As String, ByVal lpszFile As String, ByVal lpszParams As String, ByVal lpszDir As String, ByVal FsShowCmd As Long) As Long

Public Function OpenFile(ByVal FileName As String) As Long

   OpenFile = ShellExecute(0, "Open", FileName, "", "C:\ALL_pdf_Cut_Sheets\Actuators\", 1)
End Function

like this?
sub file_get
OpenFile "C:\ALL_pdf_Cut_Sheets\Actuators\ms8105a1008"
End Sub
Title: Re: VBa
Post by: Keith™ on June 08, 2010, 11:22:03 AM
you need to include the file extension ..

Try this:
Code: [Select]
Option Explicit

Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpszOp As String, ByVal lpszFile As String, ByVal lpszParams As String, ByVal lpszDir As String, ByVal FsShowCmd As Long) As Long

Public Function OpenFile(ByVal FileName As String) As Long
   OpenFile = ShellExecute(0, "Open", FileName, "", "C:\ALL_pdf_Cut_Sheets\Actuators\", 1)
End Function

Sub file_get()
   OpenFile "C:\ALL_pdf_Cut_Sheets\Actuators\ms8105a1008.pdf"
End Sub

In your form, make the action of the click event for your button call file_get
Title: Re: VBa
Post by: krampaul82 on June 09, 2010, 09:54:46 AM
Suh-Wheet that was it. Thanks for sticking with me Keith.
Title: Re: VBa
Post by: Keith™ on June 09, 2010, 09:56:12 AM
no problem
Title: Re: VBa
Post by: jgr on June 18, 2010, 08:02:52 PM
For print Try with verb "print" (parameter lpOperation)

ShellExecute(0, "print",....