Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using VB5 to open a pdf file 1

Status
Not open for further replies.

woodglass

Programmer
Jun 3, 2001
10
GB
I know how to use the shell function to run Adobe Acrobat from within VB, but how can I open a named file in Acrobat using shell or some other function?
 
easiest way would be
Call Shell("D:\ACROBAT\ACROBAT.EXE C:\COPYRI~1.PDF")
 
Thanks Justin,
This works fine as long as the pathname to the document I wish to open does not contain any space characters, e.g.:

Call Shell("C:\Program Files\Adobe\Acrobat 4.0\Reader\AcroRd32.exe C:\ReadMe.pdf")

will work, but:

Call Shell("C:\Program Files\Adobe\Acrobat 4.0\Reader\AcroRd32.exe C:\Program Files\Adobe\Acrobat 4.0\Reader\ReadMe.pdf")

will not, as the path to the pdf file contains spaces.
Any ideas?
 
You can use this function

Public Function GetDosName(ByVal sExpr As String) As String
Dim oFSO As Scripting.FileSystemObject
Dim oFile As Scripting.File
Dim oFolder As Scripting.Folder

On Error GoTo ERRORHANDLER

Set oFSO = New Scripting.FileSystemObject

sExpr = oFSO.GetAbsolutePathName(sExpr)

If oFSO.FileExists(sExpr) Then
Set oFile = oFSO.GetFile(sExpr)
GetDosName = oFile.ShortPath
ElseIf oFSO.FolderExists(sExpr) Then
Set oFolder = oFSO.GetFolder(sExpr)
GetDosName = oFolder.ShortPath
Else
End If

ERRORHANDLER:
Set oFSO = Nothing
Set oFolder = Nothing
Set oFile = Nothing
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top