• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 146
  • Last Modified:

How to open a PDF file in VB

Hello!

I would like to open a PDF file in VB 6.0. I currently use a WebBrowser control to show a PDF file, but it requires an extra form. Is there a way to open a PDF file in a web browser without using a WebBrowser control?

Thanks.
Peter
0
k0ndi
Asked:
k0ndi
  • 4
  • 2
1 Solution
 
makmanCommented:
Hi k0ndi,
U can use AppActivate command (Application Activate command)
just go through the following code
same way use PDF file here.
In web browse in activate method you can give this command.
Private dblWordID As Double
'// runs word
Private Sub cmdRunWord_Click()
    dblWordID = Shell("notepad", vbNormalFocus)
End Sub
'// activates word at a later stage
Private Sub cmdActivateWord_Click()
    AppActivate dblWordID
End Sub
Regards,
Makman
0
 
makmanCommented:
Peter just go through the above code i have given you.
Regards,
Makman
0
 
k0ndiAuthor Commented:
Thanks Mahman. That only seems like one part of the solution, because I still need to open a document. Your code only opened an application, but I still need to open a document in the activated application.

Regards,
Peter
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
makmanCommented:
Peter,
To open a specific file in vb u can use an openfile method availabe in api
Public Declare Function OpenFile Lib "kernel32" Alias "OpenFile" (ByVal lpFileName As String, lpReOpenBuff As OFSTRUCT, ByVal wStyle As Long) As Long
u can direcly use this method to open the file in any appilcation.
Regards,
Makman.
0
 
makmanCommented:
Peter,
if it is in web check out the document.navigateto(filename)
method in browsers.
regards,
Makman.
0
 
CimperialiCommented:
If in your system something is related to that file and you want system to open it with appropriate program, use following code:
Option Explicit
Private Declare Function ShellExecute Lib "shell32.dll" 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
Const SW_SHOWNORMAL = 1

Private Sub Command1_Click()
Call launchIt("c:\yourFile.pdf")
End Sub

Private Sub launchIt(strPathAndFile As String)
    ShellExecute Me.hwnd, vbNullString, strPathAndFile, vbNullString, "C:\", SW_SHOWNORMAL
End Sub
0
 
k0ndiAuthor Commented:
Thanks both makman and Cimperiali. The ShellExecute worked like a charm. I haven't tried to use the OpenFile, but I'm sure it would work.

Thanks again.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now