VBA to open Visio and PDF (1 Viewer)

Lanason

Registered User.
Local time
Today, 00:16
Joined
Sep 12, 2003
Messages
258
Hi Guys,

I have the code below to open Word and Excel documents - does anyone know how to open Visio and PDF formats?

Code:
   Set oApp = CreateObject(Class:="Excel.Application")    'Create an instance of MS Excel
   oApp.Visible = True
   oApp.WorkBooks.Open FileName:=DocName                'Open the excel Document
Code:
    Set oApp = CreateObject(Class:="Word.Application")    'Create an instance of MS Word
    oApp.Visible = True
    oApp.Documents.Open FileName:=DocName                'Open the word Document
 

Gasman

Enthusiastic Amateur
Local time
Today, 00:16
Joined
Sep 21, 2011
Messages
14,423

isladogs

MVP / VIP
Local time
Today, 00:16
Joined
Jan 14, 2017
Messages
18,261
Another variation on this is fHandleFile which opens any file using the default application for that file type.

Available from http://access.mvps.org/access/api/api0018.htm

The code was written by Dev Ashish and works flawlessly on everything I've ever thrown at it...

Example usage:
Code:
strFileName="G:\Programs\MendipDataSystems\CommonFiles\SDA\Documentation\AppendixC.pdf"
Call fHandleFile(strFileName, WIN_NORMAL)

This code can be used to start any registered applications, including another instance of Access.
If it doesn't know what application to open the file with, it just pops up the standard "Open With.." dialog.
It can even handle URL's and mailto:

'Open a folder:
' fHandleFile("C:\TEMP",WIN_NORMAL)

'Call Email app:
' fHandleFile("mailto:bpo@yahoo.com",WIN_NORMAL)

'Open URL:
' fHandleFile("http://uk.yahoo.com";, WIN_NORMAL)

'Handle Unknown extensions:
' fHandleFile("C:\TEMP\TestThis",WIN_NORMAL)
 

Lanason

Registered User.
Local time
Today, 00:16
Joined
Sep 12, 2003
Messages
258
I'm getting this error .... any reasons why :banghead:

ByRef Argument type mismatch

ps im trying to open visio
 

Lanason

Registered User.
Local time
Today, 00:16
Joined
Sep 12, 2003
Messages
258
Call fHandleFile(DocName, WIN_NORMAL)

where the DocName is defined as path & docname & extension
 
Last edited:

isladogs

MVP / VIP
Local time
Today, 00:16
Joined
Jan 14, 2017
Messages
18,261
I don't have Visio so can't test it but fHandle file has never failed for me on a wide variety of file types

Can you post your entire code for this.

Do you have a full version of visio or just the viewer?
Does the file open if you select it direct in Windows Explorer

Another question. Are you using 64-bit Access?
 

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 19:16
Joined
May 21, 2018
Messages
8,568
Is DocName explicitly declared as a string
Dim DocName as string

If you do this
dim DocName
or
Dim DocName as variant
Or do not have option explicit set and just
DocName = ....

Then you will get a datatype mismatch error.
Always explicitly declare variables with proper type.
 

Users who are viewing this thread

Top Bottom