none
I'm getting a compile error: Expected: ( RRS feed

  • Question

  • I am getting a compile error: Expected: ( error. 

    The code is below, the point upon where the error is coming from is below it.

        With wsJL
    
        strComp = Range("A1") ' assumes company name in A1
        strPart = CleanName(Range("C1")) ' assumes part in C1
        strPath = CleanName(Range("G2"))
            If Not FolderExists(strPath & strComp)Then
    'company doesn't exist, so create full path
                FolderCreate strPath & strComp & Application.PathSeparator & strPart
    Else
    'company does exist, but does part folder
            If Not FolderExists(strPath & strComp & Application.PathSeparator & strPart) Then
                FolderCreate strPath & strComp & Application.PathSeparator & strPart
        End If
    End If
    
    End Sub
    
    Function FolderCreate(ByVal path As String) As Boolean
    
    FolderCreate = True
    Dim fso As New FileSystemObject
    
    If Functions.FolderExists(path) Then
        Exit Function
    Else
        On Error GoTo DeadInTheWater
        fso.CreateFolder path ' could there be any error with this, like if the path is really screwed up?
        Exit Function
    End If
    
    DeadInTheWater:
        MsgBox "A folder could not be created for the following path: " & path & ". Check the path name and try again."
        FolderCreate = False
        Exit Function
    
    End Function
    
    Function FolderExists(ByVal path As String) As Boolean
    
    FolderExists = False
    Dim fso As New FileSystemObject
    
    If fso.FolderExists(path) Then FolderExists = True
    
    End Function
    
    Function CleanName(strName As String) As String
    'will clean part # name so it can be made into valid folder name
    'may need to add more lines to get rid of other characters
    
        CleanName = Replace(strName, "/", "")
        CleanName = Replace(CleanName, "*", "")
        CleanName = Replace(CleanName, ".", "")
    
    End Function
    
        
        End With

    The error is at the code below. It gets stuck on the & on each row. I don't know why, can someone please help me with this?

            If Not FolderExists(strPath & strComp)Then
    'company doesn't exist, so create full path
                FolderCreate strPath & strComp & Application.PathSeparator & strPart
    Else
    'company does exist, but does part folder
            If Not FolderExists(strPath & strComp & Application.PathSeparator & strPart) Then
                FolderCreate strPath & strComp & Application.PathSeparator & strPart
        End If
    End If
    



    Friday, June 1, 2012 12:30 PM

Answers

  • StrComp is the name of a VBA function that compares strings, so you should not use strComp as the name of a variable. Change it to for example strCompany.


    Regards, Hans Vogelaar

    • Marked as answer by Matt Ridge Friday, June 1, 2012 2:14 PM
    Friday, June 1, 2012 12:51 PM

All replies

  • StrComp is the name of a VBA function that compares strings, so you should not use strComp as the name of a variable. Change it to for example strCompany.


    Regards, Hans Vogelaar

    • Marked as answer by Matt Ridge Friday, June 1, 2012 2:14 PM
    Friday, June 1, 2012 12:51 PM
  • StrComp is the name of a VBA function that compares strings, so you should not use strComp as the name of a variable. Change it to for example strCompany.


    Regards, Hans Vogelaar

    That got rid of the errors there thanks, now I got to figure out how to make this work with a Sub. 
    Friday, June 1, 2012 2:13 PM