OberonPlace.com Forums

OberonPlace.com Forums (http://forum.oberonplace.com/index.php)
-   CorelDRAW/Corel DESIGNER VBA (http://forum.oberonplace.com/forumdisplay.php?f=16)
-   -   Browse Dialog (http://forum.oberonplace.com/showthread.php?t=344)

ddonnahoe 21-01-2004 07:53

Browse Dialog
I am interested in creating a browse dialog command button, but have no idea where to begin. What I'm trying to do is give an optional command button that will allow the user to browse for an image file on their computer (or the network) that will be placed in the resluting document. I assume that I need a command button (DUH! LOL) and possibly a TextBox to visually store the filename for the end user until the form is dismissed. They only need to be able to select one item, if that makes a difference.

ddonnahoe 21-01-2004 08:10

I may even want to allow a list box or something to actually show the item, ie. jpg or gif, since that is what they will be primarily choosing from

shelbym 21-01-2004 08:20

Have a look at the FileConverter Script
CorelDraw 11 comes with a FileConverter Script that shows much of what you are looking for. I learn best by example on there is lots to be learned from this one little script.


ddonnahoe 21-01-2004 11:54

I have figured out how it creates the Browse Window, however, it only browses for a certain folder. I want it to browse for a file and allow this file to be the only one selected.

Alex 21-01-2004 16:12

In this case you should use GetFileBox method of CorelScriptTools object which does exactly that:


Public Sub TestFileSelection()
    Dim FileName As String
    FileName = CorelScriptTools.GetFileBox("Text Files (*.txt)|*.txt", "Please select a text file to open", 1, "", "txt")

    If FileName <> "" Then
        MsgBox "File selected was: " & FileName
    End If
End Sub

shelbym 21-01-2004 18:10

Alex’s answers are always so easy. I on the other hand tend to make things much more difficult then they need be.

Alex a question or two. The dialog your example opens says, “Save type as” and the buttons are Save and Cancel. Is there a way for it to be Open type as and the buttons Open and Cancel?

Here is a more complicated approach I found on another VBA newsgroup. Alex is this a bad approach to use? I have modified it a bit to filter for CDR files:


Private Declare Function GetOpenFileName Lib "comdlg32.dll" _
    Alias "GetOpenFileNameA" _
    (pOpenfilename As OPENFILENAME) As Long

    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

Sub ShowOpenFile()
Dim sPath As String

    OFName.lStructSize = Len(OFName)
    OFName.hwndOwner = 0&
    OFName.hInstance = 0&
    OFName.lpstrFilter = "CDR - CorelDRAW" + Chr$(0) + "*.cdr"
    OFName.lpstrFile = Space$(254)
    OFName.nMaxFile = 255
    OFName.lpstrFileTitle = Space$(254)
    OFName.nMaxFileTitle = 255
    sPath = GetBackEnd
    If sPath = vbNullString Then
        OFName.lpstrInitialDir = "c:\"
        sPath = Left(sPath, InStrRev(sPath, "\") - 1)
        If Len(Dir(sPath, vbDirectory)) > 0 Then
            OFName.lpstrInitialDir = sPath
            OFName.lpstrInitialDir = "c:\"
        End If
    End If
    OFName.lpstrTitle = "Open a CDR File (*.cdr)"
    OFName.flags = 0

    If GetOpenFileName(OFName) Then
        BrowseOpenFile = OFName.lpstrFile
        MsgBox BrowseOpenFile
        BrowseOpenFile = vbNullString
        MsgBox "No file Selected."
    End If
End Sub

Alex 21-01-2004 20:01


Originally Posted by shelbym
Alex a question or two. The dialog your example opens says, “Save type as” and the buttons are Save and Cancel. Is there a way for it to be Open type as and the buttons Open and Cancel?

Oh, sorry, my mistake. The 3rd parameter should be set to 0 instead of 1 to show the Open dialog instead of Save.

Plust the very last parameter (two optional parameters not shown in the code above) can be used to specify different caption for Open/Save button.

Sorry about the confusion.

In fact, the methods of CorelScriptTools object is an adaptation of some of internal CorelScript commands which were in the language itself. GetFileBox is one of them. There are more. You can get more information on their parameters and usage on the following page: http://www.oberonplace.com/tutor/page7.htm

Please note that CorelScript's GetFolder command is not implemented in VBA's CorelScriptTools object even though the method is present.

ddonnahoe 22-01-2004 06:56

I just realized that I didn't specify. I want this to be able to work in other VBA Capable programs, so I'm looking for something generic. What happened was, I created a form to use in CorelDRAW to fill in the blanks on our company order form. However, the salesforce doesn't have acces to Corel, but they do have access to MSWord. I am trying to convert this over to Word. I have everything but this "Browse for File" dialog thing down. I know this isn't a "Word" forum, but I was hoping there was something that VBA could let me do to access this that wasn't specifically application dependent.


shelbym 22-01-2004 08:37

The code I posted above with with with Word. Infact that is were I got it from was a Word Forum. I tried it in Word 2003 and it works file. Word also has a simple way to do this, but it will not work in Draw. See code below:

Sub Main()

    Dim fd As FileDialog
    Set fd = Application.FileDialog(msoFileDialogFilePicker)
    Dim vrtSelectedItem As Variant

    With fd
        If .Show = -1 Then
            For Each vrtSelectedItem In .SelectedItems
                MsgBox "The path is: " & vrtSelectedItem
            Next vrtSelectedItem
        End If
    End With
    Set fd = Nothing

End Sub

ddonnahoe 22-01-2004 13:55

I'm not really following you on this. I've tried using both sets of code and various changes to each, but can't seem to get it nailed down. Am I supposed to attach this to a cmdButton click or what?

All times are GMT -5. The time now is 09:45.

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