OberonPlace.com Forums  

Go Back   OberonPlace.com Forums > Developer Forums > VBA > CorelDRAW/Corel DESIGNER VBA

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 26-07-2010, 21:13
ager ager is offline
Member
 
Join Date: Jul 2010
Location: Russia
Posts: 44
Default Open file dialog

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
And old dialog window appears that do not support long file names:
The question is how to create normal Open-dialog window in CorelDraw VBA like in Excel?
Thank you!
Reply With Quote
  #2  
Old 26-07-2010, 21:20
shelbym's Avatar
shelbym shelbym is offline
Senior Member
 
Join Date: Nov 2002
Location: Cheyenne, WY
Posts: 1,769
Blog Entries: 9
Send a message via ICQ to shelbym Send a message via AIM to shelbym Send a message via MSN to shelbym Send a message via Yahoo to shelbym
Default GetFileBox

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
Best of luck,

-Shelby
Reply With Quote
  #3  
Old 26-07-2010, 21:47
ager ager is offline
Member
 
Join Date: Jul 2010
Location: Russia
Posts: 44
Default Re: GetFileBox

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
Reply With Quote
  #4  
Old 26-07-2010, 22:19
runflacruiser's Avatar
runflacruiser runflacruiser is offline
Senior Member
 
Join Date: Jun 2009
Location: Pigeon Forge, TN USA
Posts: 811
Default

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
Reply With Quote
  #5  
Old 26-07-2010, 23:57
shelbym's Avatar
shelbym shelbym is offline
Senior Member
 
Join Date: Nov 2002
Location: Cheyenne, WY
Posts: 1,769
Blog Entries: 9
Send a message via ICQ to shelbym Send a message via AIM to shelbym Send a message via MSN to shelbym Send a message via Yahoo to shelbym
Default MultiSelect

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
Best of luck,

-Shelby
Reply With Quote
  #6  
Old 27-07-2010, 00:41
ager ager is offline
Member
 
Join Date: Jul 2010
Location: Russia
Posts: 44
Default

Thank you, Shelbym! That's fantastic! This is a very thing I want! Of course, in order to create array I must just add in your code:
Code:
....
Dim arr
.....
arr=Split(strOutput, Chr(10))
The idea of Runflacruiser is also works but it's not so convenient
Reply With Quote
  #7  
Old 27-07-2010, 09:17
runflacruiser's Avatar
runflacruiser runflacruiser is offline
Senior Member
 
Join Date: Jun 2009
Location: Pigeon Forge, TN USA
Posts: 811
Default

Hi.

Very Awesome Shelby!

-John
Reply With Quote
  #8  
Old 11-03-2012, 23:42
ager ager is offline
Member
 
Join Date: Jul 2010
Location: Russia
Posts: 44
Default Modal mode

A small question to Shelby: how to set modal mode of ShowFileOpenDialog window (ShowModal=true)?
Thank you!
Reply With Quote
  #9  
Old 15-03-2012, 23:16
shelbym's Avatar
shelbym shelbym is offline
Senior Member
 
Join Date: Nov 2002
Location: Cheyenne, WY
Posts: 1,769
Blog Entries: 9
Send a message via ICQ to shelbym Send a message via AIM to shelbym Send a message via MSN to shelbym Send a message via Yahoo to shelbym
Default ShowFileOpenDialog Modal

You just need to change the following line:
Code:
.hwndOwner = 0
to
Code:
.hwndOwner = AppWindow.Handle
Hope that helps,

-Shelby
Reply With Quote
  #10  
Old 24-08-2016, 05:49
ager ager is offline
Member
 
Join Date: Jul 2010
Location: Russia
Posts: 44
Default x64

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 05:21.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Open File (that's in clipboard) ProofingGuy CorelDRAW/Corel DESIGNER VBA 5 12-07-2011 14:12
Open text edit dialog Albert CorelDRAW/Corel DESIGNER VBA 0 29-05-2009 08:40
Open & Save dialog of vista explorer by VBA aakkaarr CorelDRAW/Corel DESIGNER VBA 3 19-03-2009 05:23
open fill dialog diwin CorelDRAW/Corel DESIGNER VBA 2 21-05-2007 11:21
file will not open mudhen General 3 03-02-2006 04:51


All times are GMT -5. The time now is 22:21.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
Copyright © 2011, Oberonplace.com