Using GetObject 
Author Message
 Using GetObject

I would like to open a ".pdf" file from VBA using the following subroutine:

Sub  OpenPDF()
     Const loc as string = "C:\MyDcouments\PDFs\test.pdf"
     Dim PDFObj as Object
     Set PDFObj = GetObject(loc)
End Sub

When executed the error mesage # 424, Object required is produced.

Can you use GetObject to open a ".pdf" file from VBA or is there a better
way to do this?



Wed, 28 Apr 2004 22:59:21 GMT  
 Using GetObject
If PDF files are in fact objects (in the OOP sense of the word), then I
believe you have to set a reference (Tools/References) to some library that
"knows" about PDF objects, e.g. my References list includes an entry for the
Adobe Acrobat 5.0 Type Library. Is there any information on the Adobe web site
as to how to access the file?

What do you want to do with the file once it's open? If it's just to read
specific bytes of information, you could use VBA's low-level I/O statements,
i.e.

  Const loc as string = "C:\MyDcouments\PDFs\test.pdf"
  F = FreeFile()
  Open Loc For Binary As #F

For other procedures to read the file, make the routine a function instead of
a Sub and pass back the file number as the result.



Quote:
>I would like to open a ".pdf" file from VBA using the following subroutine:

>Sub  OpenPDF()
>     Const loc as string = "C:\MyDcouments\PDFs\test.pdf"
>     Dim PDFObj as Object
>     Set PDFObj = GetObject(loc)
>End Sub

>When executed the error mesage # 424, Object required is produced.

>Can you use GetObject to open a ".pdf" file from VBA or is there a better
>way to do this?



Thu, 29 Apr 2004 03:17:58 GMT  
 Using GetObject
Hi William,
GetObject will only find an open (running) program. Otherwise it fails. (see
VBA help)

John
Here is some code from Excel VBA help.(XL2K)

' Declare necessary API routines:
Declare Function FindWindow Lib "user32" Alias _
"FindWindowA" (ByVal lpClassName as String, _
                    ByVal lpWindowName As Long) As Long

Declare Function SendMessage Lib "user32" Alias _
"SendMessageA" (ByVal hWnd as Long,ByVal wMsg as Long, _
                    ByVal wParam as Long, _
                    ByVal lParam As Long) As Long

Sub GetExcel()
    Dim MyXL As Object    ' Variable to hold reference
                                ' to Microsoft Excel.
    Dim ExcelWasNotRunning As Boolean    ' Flag for final release.

' Test to see if there is a copy of Microsoft Excel already running.
    On Error Resume Next    ' Defer error trapping.
' Getobject function called without the first argument returns a
' reference to an instance of the application. If the application isn't
' running, an error occurs.
    Set MyXL = Getobject(, "Excel.Application")
    If Err.Number <> 0 Then ExcelWasNotRunning = True
    Err.Clear    ' Clear Err object in case error occurred.

' Check for Microsoft Excel. If Microsoft Excel is running,
' enter it into the Running Object table.
    DetectExcel

' Set the object variable to reference the file you want to see.
    Set MyXL = Getobject("c:\vb4\MYTEST.XLS")

' Show Microsoft Excel through its Application property. Then
' show the actual window containing the file using the Windows
' collection of the MyXL object reference.
    MyXL.Application.Visible = True
    MyXL.Parent.Windows(1).Visible = True
     Do manipulations of your  file here.
    ' ...
' If this copy of Microsoft Excel was not running when you
' started, close it using the Application property's Quit method.
' Note that when you try to quit Microsoft Excel, the
' title bar blinks and a message is displayed asking if you
' want to save any loaded files.
    If ExcelWasNotRunning = True Then
        MyXL.Application.Quit
    End IF

    Set MyXL = Nothing    ' Release reference to the
                                ' application and spreadsheet.
End Sub

Sub DetectExcel()
' Procedure dectects a running Excel and registers it.
    Const WM_USER = 1024
    Dim hWnd As Long
' If Excel is running this API call returns its handle.
    hWnd = FindWindow("XLMAIN", 0)
    If hWnd = 0 Then    ' 0 means Excel not running.
        Exit Sub
    Else
    ' Excel is running so use the SendMessage API
    ' function to enter it in the Running Object Table.
        SendMessage hWnd, WM_USER + 18, 0, 0
    End If
End Sub



Quote:
> I would like to open a ".pdf" file from VBA using the following
subroutine:

> Sub  OpenPDF()
>      Const loc as string = "C:\MyDcouments\PDFs\test.pdf"
>      Dim PDFObj as Object
>      Set PDFObj = GetObject(loc)
> End Sub

> When executed the error mesage # 424, Object required is produced.

> Can you use GetObject to open a ".pdf" file from VBA or is there a better
> way to do this?



Thu, 29 Apr 2004 18:44:21 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Using GetObject to open an Application

2. using GetObject to refer to a tab seperated file (.tsv)

3. using GetObject to refer to a tab seperated file (.tsv)

4. Problem using GetObject to reference an Excel 97 add-in

5. Using GETOBJECT to fire up a word doc

6. Bypassing autoexec using GetObject

7. Automation Error Incorrect Function using GetObject

8. Using getobject() with 1+ Excel open

9. Automation Error Using GetObject Access97

10. using GETOBJECT in Access 2000


 
Powered by phpBB® Forum Software © phpBB Group