![]() |
#1
|
|||
|
|||
![]()
I’m trying to create Openfile dialog in VBA which allow to user select multifiles like in Excel VBA:
![]() It perform quite simple in Excel with function Application.GetOpenFilename(FileFilter:="All files (*.*), *.*", Title:="Get File", MultiSelect:=True). But in CorelDraw I know only one way to do this: Code:
Set objDialog = CreateObject("UserAccounts.CommonDialog") objDialog.Filter = "All Files|*.*" objDialog.flags = &H200 objDialog.FilterIndex = 1 objDialog.InitialDir = "C:\My Documents\" intFileCount = objDialog.ShowOpen ![]() The question is how to create normal Open-dialog window in CorelDraw VBA like in Excel? Thank you! |
#2
|
||||
|
||||
![]()
Try using the CorelScriptTools.GetFileBox. Here is a very simple example:
Code:
Sub MyFolderDialog() Dim sFileName As String sFileName = CorelScriptTools.GetFileBox("All Files (*.*)|*.*", "Select a file", 0, "c:\Temp\*.*") End Sub -Shelby |
#3
|
|||
|
|||
![]()
Yes, it's simple, but it don't allow to select several files. I want to get array of filepathes, not a one string. May be I need WinAPI but it incomprehensible thing for me
![]() |
#4
|
||||
|
||||
![]()
Hi.
Try a listbox. Use getFileBox for the folder string. Create a form and populate listbox with the files in a folder after selecting path.\ Then you'll have the folder path string and a variant array of as many files as you select. -John |
#5
|
||||
|
||||
![]()
Alright here is a way to do the MultiSelect, returned as a Collection. You could modify to an array if you like. :-) Hopefully it does the trick for you.
Code:
Public Const OFN_ALLOWMULTISELECT = &H200& Public Const OFN_EXPLORER = &H80000 Public Const OFN_FILEMUSTEXIST = &H1000& Public Const OFN_HIDEREADONLY = &H4& Public Const OFN_PATHMUSTEXIST = &H800& Public Declare Function GetOpenFileName Lib "comdlg32.dll" Alias _ "GetOpenFileNameA" (pOpenFileName As OPENFILENAME) As Long Public 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 Type Private Sub ShowFileOpenDialog(ByRef FileList As Collection) Dim OpenFile As OPENFILENAME Dim lReturn As Long Dim FileDir As String Dim FilePos As Long Dim PrevFilePos As Long With OpenFile .lStructSize = Len(OpenFile) .hwndOwner = 0 .hInstance = 0 .lpstrFilter = "CDR - CorelDRAW (*.cdr)" + Chr(0) + "*.cdr" + _ Chr(0) + "All Files (*.*)" + Chr(0) + "*.*" + Chr(0) + Chr(0) .nFilterIndex = 1 .lpstrFile = String(4096, 0) .nMaxFile = Len(.lpstrFile) - 1 .lpstrFileTitle = .lpstrFile .nMaxFileTitle = .nMaxFile .lpstrInitialDir = "c:\" .lpstrTitle = "Open Drawings" .flags = OFN_HIDEREADONLY + _ OFN_PATHMUSTEXIST + _ OFN_FILEMUSTEXIST + _ OFN_ALLOWMULTISELECT + _ OFN_EXPLORER lReturn = GetOpenFileName(OpenFile) If lReturn <> 0 Then FilePos = InStr(1, .lpstrFile, Chr(0)) If Mid(.lpstrFile, FilePos + 1, 1) = Chr(0) Then FileList.Add .lpstrFile Else FileDir = Mid(.lpstrFile, 1, FilePos - 1) Do While True PrevFilePos = FilePos FilePos = InStr(PrevFilePos + 1, .lpstrFile, Chr(0)) If FilePos - PrevFilePos > 1 Then FileList.Add FileDir + "\" + _ Mid(.lpstrFile, PrevFilePos + 1, _ FilePos - PrevFilePos - 1) Else Exit Do End If Loop End If End If End With End Sub Sub SelectFiles() Dim colFileList As New Collection Dim lngI As Long Dim strOutput As String ShowFileOpenDialog colFileList With colFileList If .Count > 0 Then strOutput = "The following files were selected:" + vbCrLf For lngI = 1 To .Count strOutput = strOutput + .Item(lngI) + vbCrLf Next MsgBox strOutput Else MsgBox "No files were selected!" End If End With End Sub -Shelby |
#6
|
|||
|
|||
![]()
Thank you, Shelbym! That's fantastic!
![]() Code:
.... Dim arr ..... arr=Split(strOutput, Chr(10)) |
#7
|
||||
|
||||
![]()
Hi.
Very Awesome Shelby! -John |
#8
|
|||
|
|||
![]()
A small question to Shelby: how to set modal mode of ShowFileOpenDialog window (ShowModal=true)?
Thank you! |
#10
|
|||
|
|||
![]()
A question to Shelby again!
How to make working version of this code for CorelDRAW 64-bit? I try to use PtrSafe and LongPtr, but it does not help. Last edited by ager; 25-08-2016 at 06:21. |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Open File (that's in clipboard) | ProofingGuy | CorelDRAW/Corel DESIGNER VBA | 5 | 12-07-2011 15:12 |
Open text edit dialog | Albert | CorelDRAW/Corel DESIGNER VBA | 0 | 29-05-2009 09:40 |
Open & Save dialog of vista explorer by VBA | aakkaarr | CorelDRAW/Corel DESIGNER VBA | 3 | 19-03-2009 06:23 |
open fill dialog | diwin | CorelDRAW/Corel DESIGNER VBA | 2 | 21-05-2007 12:21 |
file will not open | mudhen | General | 3 | 03-02-2006 05:51 |