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
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