how to open visio file by Excel VBA

  • Thread starter Thread starter moonhk
  • Start date Start date
M

moonhk

Hi All

how to open visio file by Excel VBA ?


I try below coding not ok.

Set oApp = CreateObject("Visio.Application")
oApp.Visible = True
MsgBox FN
oApp.Documents.Open FN
 
The following code works for me with Excel 2007 and Visio 2007.


Sub OpenVisioDoc()
Dim FName As String
Dim VisioApp As Object

On Error Resume Next
Set VisioApp = GetObject(, "Visio.Application")
If VisioApp Is Nothing Then
Set VisioApp = CreateObject("Visio.Application")
If VisioApp Is Nothing Then
MsgBox "Can't connect to Visio"
Exit Sub
End If
End If
On Error GoTo 0
FName = "C:\Path\FileName.vsd"

VisioApp.documents.Open FName '
VisioApp.Visible = True
End Sub
 
The following code works for me with Excel 2007 and Visio 2007.

Sub OpenVisioDoc()
Dim FName As String
Dim VisioApp As Object

On Error Resume Next
Set VisioApp = GetObject(, "Visio.Application")
If VisioApp Is Nothing Then
Set VisioApp = CreateObject("Visio.Application")
If VisioApp Is Nothing Then
MsgBox "Can't connect to Visio"
Exit Sub
End If
End If
On Error GoTo 0
FName = "C:\Path\FileName.vsd"

VisioApp.documents.Open FName '
VisioApp.Visible = True
End Sub









- Åã¥Ü³Q¤Þ¥Î¤å¦r -

Using below coding works.

'~~ http://support.microsoft.com/kb/309603
Set oApp = CreateObject("Visio.Application")
Set docsObj = oApp.Documents
Set DocObj = docsObj.Open(FN)
' Clear the variable from memory.
Set docsObj = Nothing
Set DocObj = Nothing
Set oApp = Nothing
 
Back
Top