+ Reply to Thread
Results 1 to 4 of 4

Find current directory - Optional string

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    01-15-2010
    Location
    Jhb, South Africa
    MS-Off Ver
    2007, 2010, 2016
    Posts
    275

    Find current directory - Optional string

    Hi Guys,

    Having problems so late in the afternoon...

    I have a piece of code that is suppose to defualt to the file's current directory if not specified but for some reason this does not work...

    Am I refering to ismissing() incorrect or what?

    Sub pass()
        
        Dim thename As String: thename = "myWorkbook"
        Dim thetype As String: thetype = "xltm"
        Dim direct As String: direct = "C:\"
    
        Call mod_SaveAs(thename, thetype)
        
    End Sub
    
    Function mod_SaveAs(file_Name As String, fileType As String, Optional newDir As String)
    
        Dim completeName As String, file_ext As String
        
        If IsMissing(newDir) Then
            newDir = ActiveWorkbook.Path 'whatsMyDir
        End If
        
        completeName = newDir & "/" & file_Name & "." & fileType
        
        MsgBox newDir
        MsgBox file_Name
        MsgBox fileType
        MsgBox completeName
        MsgBox "Save complete"
    
    End Function
    Last edited by Jacques Grobler; 10-03-2011 at 01:32 AM.
    Jacques


  2. #2
    Valued Forum Contributor quekbc's Avatar
    Join Date
    01-18-2010
    Location
    Sydney, Australia
    MS-Off Ver
    2010, 2013, 2016
    Posts
    1,149

    Re: Find current directory - Optional string

    Firstly, the "/" needs to be "\"

    Since newDir has been defined as a string, using this would solve the issue.

    If newDir = vbNullString Then

  3. #3
    Forum Expert Colin Legg's Avatar
    Join Date
    03-30-2008
    Location
    UK
    MS-Off Ver
    365
    Posts
    1,256

    Re: Find current directory - Optional string

    Just to elaborate on the previous reply, IsMissing() is used to test Variant types; you can't use it (succesfully) on String types. Have a look at the "IsMissing Function" topic in your VBA helpfile for more information.
    Hope that helps,

    Colin

    RAD Excel Blog

  4. #4
    Forum Contributor
    Join Date
    01-15-2010
    Location
    Jhb, South Africa
    MS-Off Ver
    2007, 2010, 2016
    Posts
    275

    Re: Find current directory - Optional string

    Hahaha, finger trouble... Thanks for the help quekbc,

    Colin, thanks for the clarification.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1