FileDialog + Visio 2003 dilemma

E

Eva Ajtay

Hi,

Here is the dilemma: I want to show a simple dialog box, a
standard one, which lets the user choose an image file, and me to retrive the
path to the chosen file. I use MS Visio 2003.

Precisely, MS Visio 2003. Now, I managed to do this unde Word
and Excel, and the same Visual Basic code doesn't work with Visio. The 3
versions of code that I've tried are:

Public Sub altShapeAdded(ByVal vsoShape As Visio.IVShape)
Dim cdlg As Object

Set cdlg = CreateObject("MSComDlg.commonDialog")
With cdlg
.Filter = "Images|*.jpg"
.Application.Visible = True
.Show
.ApplicationVisible = True
MsgBox .FileName
.Application.Quit
End With

Set cdlg = Nothing
End Sub

----> error on line 3 – impossible to create the object

------------------------------------------
version 2)

Public Sub marche_pas_ShapeAdded(ByVal vsoShape As Visio.IVShape)
Dim cale As Variant

'Declare a variable as a FileDialog object.
Dim FD As FileDialog

'Create a FileDialog object as a File Picker dialog box.
Set FD = Application.FileDialog(msoFileDialogFilePicker)

FD.Title = "bla bla"
'fd.InitialFileName = "H:\visiotemp\"
FD.Show
FD.AllowMultiSelect = False

' Declare a variable to contain the path of each selected item. Even
though
' the path is a String, the variable must be a Variant because For
Each...Next
' routines only work with Variants and Objects.
Dim vrtSelectedItem As Variant

FD.AllowMultiSelect = False
'fd.Filters.Add "JPEG files", "*.jpg", 1
'fd.Filters.Add "BMP files", "*.bmp"; 2
If FD.Show = 0 Then
MsgBox "vous avez appuye Cancel..."
Else
vrtSelectedItem = FD.SelectedItems
MsgBox "The path is: " & vrtSelectedItem
End If
cale = FD.SelectedItems(1)

Set FD = Nothing
end sub

-----> error, "the object doesn't have this property or method"

----------------------------------
version 3)

Public Sub subVisioOpenViaDialogue()

With Office.FileSearch
If .Execute() > 0 Then
MsgBox "There were " & .FoundFiles.Count & " file(s) found."
For i = 1 To .FoundFiles.Count
MsgBox .FoundFiles(i)
Next i
Else
MsgBox "There were no files found."
End If
End With

d.FileType = msoFileTypeDocumentImagingFiles
d.Execute
MsgBox d.FileName
end sub

----> error on line 2, the same as above

More, the VBA editor doesn't have the ActiveX components
FileList, DirectoryList and DriveList (I even tried including threed32.ocx,
mso.dll, etc). The Office object hierarchy has a FileDialog object, but the
code doesn't work – as if the compiler wouldn't include the library, or it
would be damaged.

All I could do is:

fis = ShellExecute(wnd, "explore", "explorer.exe", "c:\program files", "", 1)

and

ShellExecute hwnd, "open", Left(buffer, Length) & "\explorer.exe",
"c:\program files", "", 1

and

Application.DoCmd(vsoFileOpen)

but none of this allows me to have the path to the file.

Any ideas would help. Thanks!

Eva
 
J

JuneTheSecond

I think there may be no way in visio, my recommendation is press right hand
button of the mouse on the file name and select a menu,property.
 
A

Al Edlund

something like this might work...

Public Sub subVisioOpenViaDialogue()

Dim docObj As Visio.Document

Dim visApp As Visio.Application 'Visio Application Object

subVisioOpenApplication()

visApp = GetObject(, "Visio.Application")

visApp.Application.DoCmd(visCmdFileOpen)

docObj = visApp.ActiveDocument

End Sub
 
J

JuneTheSecond

If you can make VB6 programs, one idea is to make an addon to open jpg file.
It is called from addon menu on Visio scope.
VB6 has some controls for file to open.
The code is not complicated, for example.

Private Sub Command1_Click()
Dim app As Visio.Application
Dim FileName As String
Set app = GetObject(, "Visio.Application")

FileName = Me.Dir1.Path & "\" & Me.Text1.Text
app.Documents.Open FileName
MsgBox FileName
Unload Me
End Sub

Private Sub Dir1_Change()
File1.Path = Dir1.Path
End Sub

Private Sub Drive1_Change()
Dir1.Path = Drive1.Drive
End Sub

Private Sub File1_Click()
Text1.Text = File1.FileName
End Sub
 
E

Eva Ajtay

Al,

Thanks for your good intentions.
In fact, I already tried, as below, Application.DoCmd, and from my
observations DoCmd allows just to call options available in the Visio menus.
So, in this case, FileOpen, which allows the user to choose a file and open
it in a new Visio document. It doesn't allow me to retrive the path to that
file.

Thanks for your time and reply. Please write to me again if you have
any other ideas.
Eva
 
D

Dr. Stephan Kassanke

Eva Ajtay said:
Hi,

Here is the dilemma: I want to show a simple dialog box, a
standard one, which lets the user choose an image file, and me to retrive
the
path to the chosen file. I use MS Visio 2003.

Precisely, MS Visio 2003. Now, I managed to do this unde Word
and Excel, and the same Visual Basic code doesn't work with Visio. The 3
versions of code that I've tried are:

Public Sub altShapeAdded(ByVal vsoShape As Visio.IVShape)
Dim cdlg As Object

Set cdlg = CreateObject("MSComDlg.commonDialog")
With cdlg
.Filter = "Images|*.jpg"
.Application.Visible = True
.Show
.ApplicationVisible = True
MsgBox .FileName
.Application.Quit
End With

Set cdlg = Nothing
End Sub

----> error on line 3 - impossible to create the object

------------------------------------------
version 2)

Public Sub marche_pas_ShapeAdded(ByVal vsoShape As Visio.IVShape)
Dim cale As Variant

'Declare a variable as a FileDialog object.
Dim FD As FileDialog

'Create a FileDialog object as a File Picker dialog box.
Set FD = Application.FileDialog(msoFileDialogFilePicker)

FD.Title = "bla bla"
'fd.InitialFileName = "H:\visiotemp\"
FD.Show
FD.AllowMultiSelect = False

' Declare a variable to contain the path of each selected item. Even
though
' the path is a String, the variable must be a Variant because For
Each...Next
' routines only work with Variants and Objects.
Dim vrtSelectedItem As Variant

FD.AllowMultiSelect = False
'fd.Filters.Add "JPEG files", "*.jpg", 1
'fd.Filters.Add "BMP files", "*.bmp"; 2
If FD.Show = 0 Then
MsgBox "vous avez appuye Cancel..."
Else
vrtSelectedItem = FD.SelectedItems
MsgBox "The path is: " & vrtSelectedItem
End If
cale = FD.SelectedItems(1)

Set FD = Nothing
end sub

-----> error, "the object doesn't have this property or method"

----------------------------------
version 3)

Public Sub subVisioOpenViaDialogue()

With Office.FileSearch
If .Execute() > 0 Then
MsgBox "There were " & .FoundFiles.Count & " file(s) found."
For i = 1 To .FoundFiles.Count
MsgBox .FoundFiles(i)
Next i
Else
MsgBox "There were no files found."
End If
End With

d.FileType = msoFileTypeDocumentImagingFiles
d.Execute
MsgBox d.FileName
end sub

----> error on line 2, the same as above

More, the VBA editor doesn't have the ActiveX components
FileList, DirectoryList and DriveList (I even tried including
threed32.ocx,
mso.dll, etc). The Office object hierarchy has a FileDialog object, but
the
code doesn't work - as if the compiler wouldn't include the library, or it
would be damaged.

All I could do is:

fis = ShellExecute(wnd, "explore", "explorer.exe", "c:\program files", "",
1)

and

ShellExecute hwnd, "open", Left(buffer, Length) & "\explorer.exe",
"c:\program files", "", 1

and

Application.DoCmd(vsoFileOpen)

but none of this allows me to have the path to the file.

Any ideas would help. Thanks!

Eva

Hi Eva,

have a look at the common dialogs. e.g.
http://officeone.mvps.org/vba/display_file_open_common_dialog.html presents
a sample how to use them in VBA.

cheers,
Stephan
 
D

Dr. Stephan Kassanke

Hi Eva,

to be more precisely: You are most probably missing a reference to the
common dialog ocx in (via menu Tools/References). That's the reason why the
error is thrown in line 3. the sample I referenced
(http://officeone.mvps.org/vba/display_file_open_common_dialog.html) is
based on API calls and does not need the reference.

Another approach to solve your dilemma is to check the references in Word
and Excel where your code is working and tick the missing references in
Visio.

Stephan
 
E

Eva Ajtay

June,

Merci for your reply.
As I mentionned in my first post (excessively long, it's true), I
can't find the (ActiveX?) components FileList, DirectoryList and DriveList -
which, I have read, exist somewhere, but not in the libraries I see with the
Visual Basic Editor.
Should I try to create a form with an ordinary Visual Basic 6
editor (which one?) and import the file in the Visio template? Or do you
think it's a library installation problem? I already called our support
service, they didn't reply yet.
Thanks for your help. Have a nice week!
Eva
 
J

JuneTheSecond

There is a new example!
Please, add a refference to the "Excel Object Type Libraly"
I hope this might help you.

Sub test()
Dim x As New Excel.Application
Dim fd As Office.FileDialog
Dim f As String
Dim shp As Visio.Shape

Set fd = x.FileDialog(msoFileDialogOpen)

With fd
If .Show = -1 Then
f = fd.SelectedItems.Item(1)
End If
End With

Set x = Nothing

MsgBox f
Set shp = ActivePage.Import(f)
shp.Text = f
End Sub
 
E

Eva Ajtay

Very ingenious, June.
Your solution works!
It's funny, too : pressing "Open" opens Excel, with a blank window - but I
think we can add x.Quit or Close to get rid of it.
Thanks for your help.
 
E

Eva Ajtay

Stephan,

This solution works perfectly, it's exactly what I needed!
Thanks a lot for it.
 
E

Eva Ajtay

Stephan,

See the last post by June, which works too - apparently the FileDialog
object is in the Excel and Word object hierchies, but not in Visio's.
As for the reference to comdlg (?), I don't know how to include it...
Although I tried.
 
E

Eva Ajtay

I don't understand, sorry - where should I make a right-click? Which
file name?

"JuneTheSecond" a écrit :
 
D

Dr. Stephan Kassanke

Eva Ajtay said:
Stephan,

This solution works perfectly, it's exactly what I needed!
Thanks a lot for it.

Eva,

You are welcome. I am glad i could help.

Stephan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top