Topic
Common dialog control
Page d'accueil ' Communauté ' Automation et VBA ' Contrôle de dialogue commun
- Ce sujet contient 10 réponses, 3 participants et a été mis à jour pour la dernière fois par Nicolas Beaupré, le il y a 19 années et 4 mois.
-
AuteurMessages
-
18.01.2006 à 02:23 #34975Nicolas BeaupréParticipant
Hi,
I’ve already seen in VB a control in the toolbox that allow me to select a path and a file by browsing in my computer with an automatic dialog window such as the one in attachment. The dialog should return a string containing the path of the file.
[img]uid1597_select path.JPG[/img]
Usually this component can be added to the toolbox by right-clicking on it a choose “additionnal controls”. I know the control I’m looking for is a “Common Dialog Control”. The problem is : when I clik to add ths control to my form, I got this message : [i]the control cannot be created because it is not properly licensed[/i]. I’ve asked for it on different forum and the problem seem to come from flexpro.Microsoft have a patch to solve this problem, but it need to have VB6.0 installed, not a VBA application.
http://support.microsoft.com/defaul…kb;EN-US;194751
Is there another way I can get my dialog window ?
Thanks18.01.2006 à 02:23 #34985Nicolas BeaupréParticipantHi,
I’ve already seen in VB a control in the toolbox that allow me to select a path and a file by browsing in my computer with an automatic dialog window such as the one in attachment. The dialog should return a string containing the path of the file.
[img]uid1597_select path.JPG[/img]
Usually this component can be added to the toolbox by right-clicking on it a choose “additionnal controls”. I know the control I’m looking for is a “Common Dialog Control”. The problem is : when I clik to add ths control to my form, I got this message : [i]the control cannot be created because it is not properly licensed[/i]. I’ve asked for it on different forum and the problem seem to come from flexpro.Microsoft have a patch to solve this problem, but it need to have VB6.0 installed, not a VBA application.
http://support.microsoft.com/defaul…kb;EN-US;194751
Is there another way I can get my dialog window ?
Thanks18.01.2006 à 04:02 #34976Bernhard KantzParticipantYou need a [b]design-time[/b] license for the “Common Dialog Control”. This design time license comes together with VB 6.0, unfortunately not with VBA.
So if you have VB installed on your system you can use the control also in VBA. If you redistribute a VBA project which uses the control and you simply install (copy+register) the control on the target machine it will work fine at [b]run-time[/b]. On the other hand you will not be able to add a new instance of the control on the target machine.To get the dialog box without the “Common Dialog Control” is possible, as the functionality is provided by a Windows API. This requires some more work, see for instance [url]http://www.activevb.de/tipps/vb6tipps/tipp0368.html[/url] for a VB-example. This should basically work also with VBA.
Support
support@weisang.com18.01.2006 à 05:16 #34977Nicolas BeaupréParticipantThen, why is it possible to call this windows in word or excel VBA and not in flexpro ?
In excel, I open it with that line : Application.GetOpenFileName
And in word : Application.Dialogs(wdDialogFileOpen).Display
18.01.2006 à 20:12 #34978Bernhard KantzParticipantThis is possible, because Word and Excel have (re-)implemented the Open-File-dialog-box functionality in their object model. As this is a rather generic functionality it is currently missing from the object model of FlexPro 7.0 (of cause it might be added in a future version).
As pointed out before it is no problem to use the Windows API directly. If you prefer an OCX based approach you might take a look at the pages of the Common Controls Replacement Project, especially at [url]http://ccrp.mvps.org/controls/ccrpfiledlg5.htm[/url].Support
support@weisang.com18.01.2006 à 23:34 #34979Nicolas BeaupréParticipantThanks,
The API method is working fine!
18.01.2006 à 23:48 #34980Nicolas BeaupréParticipantIn the same kind, how is it possible to just select a path ? I would like the user to select an empty (or not) folder where he want a batch of files to be exported bye the VBA macro… The API function above only allow us to select a specific file, not a path.
(sorry I can’t dig myself on the website you gave me because I don’t know a word of German!)19.01.2006 à 01:38 #34981Bernhard KantzParticipantThe SHBrowseForFolder API can be used for folder selection. A Google search for “SHBrowseForFolder VBA” should reveal some application examples.
Support
support@weisang.com10.03.2009 à 23:47 #34982Stefan PalaveevParticipantThe API method from the page [url]http://www.activevb.de/tipps/vb6tipps/tipp0368.html[/url] you refer to is not working because of:
[img]uid4536_Fehler_MehWnd.png[/img]
What is an alternative handle, which works?
11.03.2009 à 02:00 #34983Bernhard KantzParticipantThis code is an example for Visual Basic. In VBA there is no window handle.
Try [b]Nothing[/b] instead of [b]Me.hWnd[/b].12.03.2009 à 20:31 #34984Stefan PalaveevParticipantHi,
finally I was successful. For all of you having the same problems here the code for opening a common dialog windows for files and for folders.[code]Private Declare Function GetOpenFileName Lib “comdlg32.dll” _
Alias “GetOpenFileNameA” (pOpenfilename As OPENFILENAME) _
As LongDeclare Function SHGetPathFromIDList Lib “shell32.dll” _
Alias “SHGetPathFromIDListA” (ByVal pidl As Long, _
ByVal pszPath As String) As LongDeclare Function SHBrowseForFolder Lib “shell32.dll” _
Alias “SHBrowseForFolderA” (lpBrowseInfo As BROWSEINFO) As LongPrivate Type OPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
Flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End TypePublic Type BROWSEINFO
hOwner As Long
pidlRoot As Long
pszDisplayName As String
lpszTitle As String
ulFlags As Long
lpfn As Long
lParam As Long
iImage As Long
End TypePublic Const OFN_ALLOWMULTISELECT As Long = &H200&
Public Const OFN_CREATEPROMPT As Long = &H2000&
Public Const OFN_ENABLEHOOK As Long = &H20&
Public Const OFN_ENABLETEMPLATE As Long = &H40&
Public Const OFN_ENABLETEMPLATEHANDLE As Long = &H80&
Public Const OFN_EXPLORER As Long = &H80000
Public Const OFN_EXTENSIONDIFFERENT As Long = &H400&
Public Const OFN_FILEMUSTEXIST As Long = &H1000&
Public Const OFN_HIDEREADONLY As Long = &H4&
Public Const OFN_LONGNAMES As Long = &H200000
Public Const OFN_NOCHANGEDIR As Long = &H8&
Public Const OFN_NODEREFERENCELINKS As Long = &H100000
Public Const OFN_NOLONGNAMES As Long = &H40000
Public Const OFN_NONETWORKBUTTON As Long = &H20000
Public Const OFN_NOREADONLYRETURN As Long = &H8000&
Public Const OFN_NOTESTFILECREATE As Long = &H10000
Public Const OFN_NOVALIDATE As Long = &H100&
Public Const OFN_OVERWRITEPROMPT As Long = &H2&
Public Const OFN_PATHMUSTEXIST As Long = &H800&
Public Const OFN_READONLY As Long = &H1&
Public Const OFN_SHAREAWARE As Long = &H4000&
Public Const OFN_SHAREFALLTHROUGH As Long = 2&
Public Const OFN_SHARENOWARN As Long = 1&
Public Const OFN_SHAREWARN As Long = 0&
Public Const OFN_SHOWHELP As Long = &H10&Public Function ShowOpen(Filter As String, Flags As Long, hWnd As Long) As String
Dim Buffer As String
Dim Result As Long
Dim ComDlgOpenFileName As OPENFILENAMEBuffer = String$(128, 0)
With ComDlgOpenFileName
.lStructSize = Len(ComDlgOpenFileName)
.hwndOwner = hWnd
.Flags = Flags
.nFilterIndex = 1&
.nMaxFile = Len(Buffer)
.lpstrFile = Buffer
.lpstrFilter = Filter
End WithResult = GetOpenFileName(ComDlgOpenFileName)
If Result 0 Then
ShowOpen = Left$(ComDlgOpenFileName.lpstrFile, _
InStr(ComDlgOpenFileName.lpstrFile, _
Chr$(0)) – 1)
End If
End FunctionFunction GetDirectory(Msg) As String
Dim bInfo As BROWSEINFO
Dim path As String
Dim r As Long, x As Long, pos As Integer
With bInfo
.pidlRoot = 0&
.lpszTitle = Msg
.ulFlags = &H1
End With
x = SHBrowseForFolder(bInfo)
path = Space$(512)
r = SHGetPathFromIDList(ByVal x, ByVal path)
If r Then
pos = InStr(path, Chr$(0))
GetDirectory = Left(path, pos – 1)
Else
GetDirectory = “”
End If
End FunctionSub ProgramStart()
‘——– Choose a File—————-
Dim sFile As StringDim Filter As String, Flags As Long
Flags = OFN_FILEMUSTEXIST Or OFN_HIDEREADONLY Or _
OFN_PATHMUSTEXIST
Filter = “FlexPro (*.fpd)”sFile = ShowOpen(Filter, Flags, 0)
‘——————————————‘——-Choose a Folder————-
Dim sFolder As String
sFolder = GetDirectory(“Choose a Folder”)
‘—————————————
End Sub[/code]
-
AuteurMessages
- Vous devez être connecté pour répondre à ce sujet.