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 20-06-2005, 11:03
ddonnahoe's Avatar
ddonnahoe ddonnahoe is offline
Senior Member
 
Join Date: Jan 2004
Location: Louisville, KY
Posts: 552
Send a message via ICQ to ddonnahoe Send a message via AIM to ddonnahoe Send a message via MSN to ddonnahoe Send a message via Yahoo to ddonnahoe
Default Document Path

I have a macro in CD12 that I run over and over. It provides me with a file browse dialog. I am planning to change the code so that it reads the previous file location and goes to the directory on the re-run. What I am wanting to know is...

How do I convert this...
Code:
"C:\Documents and Settings\Artist\Desktop\Banners\document.ai"
...to this...
Code:
"C:\Documents and Settings\Artist\Desktop\Banners\"
What I'm planning to do is make the variable for my Initial directory equal what it was on the previous run of the macro.
Here is the actual code...
Code:
Public Sub ShowOpenFile()
Dim OFName As OPENFILENAME
Dim sPath As String
Dim GetBackEnd As String
Dim BrowseOpenFile As String
Dim n As String

    OFName.lStructSize = Len(OFName)
    OFName.hwndOwner = 0&
    OFName.hInstance = 0&
    OFName.lpstrFilter = "Image Files" + Chr$(0) + "*.ai;*.cdr;*.eps;*.pdf;*.cmx"
    OFName.lpstrFile = Space$(254)
    OFName.nMaxFile = 255
    OFName.lpstrFileTitle = Space$(254)
    OFName.nMaxFileTitle = 255
    sPath = GetBackEnd
    If sPath = vbNullString Then
        OFName.lpstrInitialDir = "D:\By Customer\"
    Else
        sPath = Left(sPath, InStrRev(sPath, "\") - 1)
        If Len(Dir(sPath, vbDirectory)) > 0 Then
            OFName.lpstrInitialDir = sPath
        Else
            OFName.lpstrInitialDir = "D:\By Customer\"
        End If
    End If
    OFName.lpstrTitle = "Select an image File (*.ai), (*.cdr), (*.cmx), (*.eps), (*.pdf)"
    OFName.flags = 0

    If GetOpenFileName(OFName) Then
        BrowseOpenFile = OFName.lpstrFile
    Else
        BrowseOpenFile = vbNullString
        MsgBox "No file Selected."
    End If
    
    boxFile.Text = BrowseOpenFile
    fname = BrowseOpenFile

End Sub
__________________
Sean
Waiting for a ride in the T.A.R.D.I.S.
Reply With Quote
  #2  
Old 20-06-2005, 14:55
shelbym's Avatar
shelbym shelbym is offline
Senior Member
 
Join Date: Nov 2002
Location: Cheyenne, WY
Posts: 1,770
Blog Entries: 10
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 Cool Little Function

I have no idea if this is the best way to do this, but here is a cool little function I found on the net that does what you wanted.

Code:
'|------------------------------------------------------|'
'| FUNCTION: ExtractPath                                |'
'| Extracts the path portion of the path & file string. |'
'|                                                      |'
'| IN: [strPathFile] - The string which has the path.   |'
'|     [AddSlash]    - Adds trailing slash.             |'
'| Returns the extracted path.                          |'
'|------------------------------------------------------|'
Sub TestExtractPathFunction()

Dim s As String
s = "C:\Documents and Settings\Artist\Desktop\Banners\document.ai"
MsgBox ExtractPath(s, True)

End Sub

Public Function ExtractPath(ByVal strPathFile As String, Optional bolAddSlash) As String

Dim intPos As Integer, intLenPos As Integer

strPathFile = Trim(strPathFile)
If IsMissing(bolAddSlash) Then bolAddSlash = False
intPos = InStr(1, strPathFile, ":") + 1

Do
    intLenPos = intPos
    intPos = InStr(intLenPos + 1, strPathFile, "\")
    If intPos = 0 Then ExtractPath = Mid(strPathFile, 1, intLenPos - 1)
Loop Until intPos = 0

If bolAddSlash Then ExtractPath = ExtractPath & IIf(Right(ExtractPath, 1) = "\", "", "\")

End Function
Reply With Quote
  #3  
Old 20-06-2005, 16:00
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default

There is even an easier way. Here is a modified Shelby's function:

Code:
Option Explicit

Sub TestExtractPathFunction()
    Dim s As String
    s = "C:\Documents and Settings\Artist\Desktop\Banners\document.ai"
    MsgBox ExtractPath(s, True)
End Sub

'|------------------------------------------------------|'
'| FUNCTION: ExtractPath                                |'
'| Extracts the path portion of the path & file string. |'
'|                                                      |'
'| IN: [strPathFile] - The string which has the path.   |'
'|     [AddSlash]    - Adds trailing slash.             |'
'| Returns the extracted path.                          |'
'|------------------------------------------------------|'
Public Function ExtractPath(ByVal strPathFile As String, Optional ByVal bolAddSlash As Boolean = False) As String
    Dim intPos As Integer
    strPathFile = Trim(strPathFile)
    intPos = InStrRev(strPathFile, "\")
    If intPos Then
        If Not bolAddSlash Then intPos = intPos - 1
        ExtractPath = Left$(strPathFile, intPos)
    Else
        ExtractPath = ""
    End If
End Function
You'll definitely recoginze the changes I've made
Reply With Quote
  #4  
Old 20-06-2005, 17:31
shelbym's Avatar
shelbym shelbym is offline
Senior Member
 
Join Date: Nov 2002
Location: Cheyenne, WY
Posts: 1,770
Blog Entries: 10
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 Once Again

Once again I marvel how simple Alex can make our complex code. Great job Alex.
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
Creating new document problems ddonnahoe Code Critique 2 20-11-2004 17:11
New document creation problem ddonnahoe CorelDRAW/Corel DESIGNER VBA 2 20-11-2004 00:26
Corel 9 Absolute document path mpp_piotrp CorelDRAW/Corel DESIGNER VBA 2 14-08-2004 00:23
Fit text to path: extend to the end of path dcsquare CorelDRAW/Corel DESIGNER VBA 1 26-05-2003 07:34
Active document issues.. wbochar CorelDRAW/Corel DESIGNER VBA 2 19-03-2003 15:15


All times are GMT -5. The time now is 11:42.


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