+ Reply to Thread
Results 1 to 7 of 7

Syntax and compile error.

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    08-15-2005
    Location
    Oklahoma
    MS-Off Ver
    2010, 2013
    Posts
    113

    Syntax and compile error.

    I am getting a syntax and compile error on the dim cou .... line. Any suggestions?

    Thanks,

    Jim

    Sub createfolders()
    '
    '
    dim cou as integer,Dim FolderStr as string, FileSys
    For cou = 1 To ActiveSheet.UsedRange.Rows.Count
    FolderStr = Format(Trim(Str(cou)), "00#") + "_" + ActiveSheet.Cells(cou, 1)
    Set FileSys = CreateObject("Scripting.FileSystemObject")
    FileSys.createfolder C:\ + RESERVES
    Next
    End Sub

  2. #2
    Chip Pearson
    Guest

    Re: Syntax and compile error.

    While you can Dim more than one variable on a line of code, you
    need to use only a single Dim keyword.

    Change
    dim cou as integer,Dim FolderStr as string, FileSys
    to
    dim cou as integer, FolderStr as string, FileSys


    --
    Cordially,
    Chip Pearson
    Microsoft MVP - Excel
    Pearson Software Consulting, LLC
    www.cpearson.com


    "Jim15" <Jim15.256urc_1143228002.2749@excelforum-nospam.com>
    wrote in message
    news:Jim15.256urc_1143228002.2749@excelforum-nospam.com...
    >
    > I am getting a syntax and compile error on the dim cou ....
    > line. Any
    > suggestions?
    >
    > Thanks,
    >
    > Jim
    >
    > Sub createfolders()
    > '
    > '
    > dim cou as integer,Dim FolderStr as string, FileSys
    > For cou = 1 To ActiveSheet.UsedRange.Rows.Count
    > FolderStr = Format(Trim(Str(cou)), "00#") + "_" +
    > ActiveSheet.Cells(cou, 1)
    > Set FileSys = CreateObject("Scripting.FileSystemObject")
    > FileSys.createfolder C:\ + RESERVES
    > Next
    > End Sub
    >
    >
    > --
    > Jim15
    > ------------------------------------------------------------------------
    > Jim15's Profile:
    > http://www.excelforum.com/member.php...o&userid=26300
    > View this thread:
    > http://www.excelforum.com/showthread...hreadid=526198
    >




  3. #3
    Jim Thomlinson
    Guest

    RE: Syntax and compile error.

    You can't use dim twice on the same line. Try either of the two following

    dim cou as integer
    Dim FolderStr as string
    dim FileSys as variant

    or

    dim cou as integer, FolderStr as string, FileSys
    --
    HTH...

    Jim Thomlinson


    "Jim15" wrote:

    >
    > I am getting a syntax and compile error on the dim cou .... line. Any
    > suggestions?
    >
    > Thanks,
    >
    > Jim
    >
    > Sub createfolders()
    > '
    > '
    > dim cou as integer,Dim FolderStr as string, FileSys
    > For cou = 1 To ActiveSheet.UsedRange.Rows.Count
    > FolderStr = Format(Trim(Str(cou)), "00#") + "_" +
    > ActiveSheet.Cells(cou, 1)
    > Set FileSys = CreateObject("Scripting.FileSystemObject")
    > FileSys.createfolder C:\ + RESERVES
    > Next
    > End Sub
    >
    >
    > --
    > Jim15
    > ------------------------------------------------------------------------
    > Jim15's Profile: http://www.excelforum.com/member.php...o&userid=26300
    > View this thread: http://www.excelforum.com/showthread...hreadid=526198
    >
    >


  4. #4
    Dave Peterson
    Guest

    Re: Syntax and compile error.

    Dim Cou As Long: Dim foldersys As String: Dim filesys As Variant

    But that's way too ugly for even me.

    Jim Thomlinson wrote:
    >
    > You can't use dim twice on the same line. Try either of the two following
    >
    > dim cou as integer
    > Dim FolderStr as string
    > dim FileSys as variant
    >
    > or
    >
    > dim cou as integer, FolderStr as string, FileSys
    > --
    > HTH...
    >
    > Jim Thomlinson
    >
    > "Jim15" wrote:
    >
    > >
    > > I am getting a syntax and compile error on the dim cou .... line. Any
    > > suggestions?
    > >
    > > Thanks,
    > >
    > > Jim
    > >
    > > Sub createfolders()
    > > '
    > > '
    > > dim cou as integer,Dim FolderStr as string, FileSys
    > > For cou = 1 To ActiveSheet.UsedRange.Rows.Count
    > > FolderStr = Format(Trim(Str(cou)), "00#") + "_" +
    > > ActiveSheet.Cells(cou, 1)
    > > Set FileSys = CreateObject("Scripting.FileSystemObject")
    > > FileSys.createfolder C:\ + RESERVES
    > > Next
    > > End Sub
    > >
    > >
    > > --
    > > Jim15
    > > ------------------------------------------------------------------------
    > > Jim15's Profile: http://www.excelforum.com/member.php...o&userid=26300
    > > View this thread: http://www.excelforum.com/showthread...hreadid=526198
    > >
    > >


    --

    Dave Peterson

  5. #5
    Forum Contributor
    Join Date
    08-15-2005
    Location
    Oklahoma
    MS-Off Ver
    2010, 2013
    Posts
    113

    "Function not defined" error message.

    I am getting a compile error on the C: RESERVES saying "function not defined". I want to create a folder called C:\RESERVES on my hard drive and subfolders with what is in column A on my Excel spreadsheet. We're almost there!

    Thanks,

    Jim

    Sub createfolders()
    '
    ' CreateFolders Macro
    ' Macro recorded 3/22/2006 by JBW
    '
    Dim cou As Integer, FolderStr As String, FileSys
    For cou = 1 To ActiveSheet.UsedRange.Rows.Count
    FolderStr = Format(Trim(Str(cou)), "00#") + "_" + ActiveSheet.Cells(cou, 1)
    Set FileSys = CreateObject("Scripting.FileSystemObject")
    FileSys.createfolder C: RESERVES
    Next
    End Sub

  6. #6
    Chip Pearson
    Guest

    Re: Syntax and compile error.

    Replace
    FileSys.createfolder C: RESERVES
    with
    FileSys.createfolder "C:\RESERVES"


    --
    Cordially,
    Chip Pearson
    Microsoft MVP - Excel
    Pearson Software Consulting, LLC
    www.cpearson.com


    "Jim15" <Jim15.25c212_1143470720.8647@excelforum-nospam.com>
    wrote in message
    news:Jim15.25c212_1143470720.8647@excelforum-nospam.com...
    >
    > I am getting a compile error on the C: RESERVES saying
    > "function not
    > defined". I want to create a folder called C:\RESERVES on my
    > hard
    > drive and subfolders with what is in column A on my Excel
    > spreadsheet.
    > We're almost there!
    >
    > Thanks,
    >
    > Jim
    >
    > Sub createfolders()
    > '
    > ' CreateFolders Macro
    > ' Macro recorded 3/22/2006 by JBW
    > '
    > Dim cou As Integer, FolderStr As String, FileSys
    > For cou = 1 To ActiveSheet.UsedRange.Rows.Count
    > FolderStr = Format(Trim(Str(cou)), "00#") + "_" +
    > ActiveSheet.Cells(cou, 1)
    > Set FileSys = CreateObject("Scripting.FileSystemObject")
    > FileSys.createfolder C: RESERVES
    > Next
    > End Sub
    >
    >
    > --
    > Jim15
    > ------------------------------------------------------------------------
    > Jim15's Profile:
    > http://www.excelforum.com/member.php...o&userid=26300
    > View this thread:
    > http://www.excelforum.com/showthread...hreadid=526198
    >




  7. #7
    Forum Contributor
    Join Date
    08-15-2005
    Location
    Oklahoma
    MS-Off Ver
    2010, 2013
    Posts
    113

    Error "File already exists"

    Thanks. I am now getting an error that says "File already exists". The routine is creating a folder called C:\RESERVES but not creating the subfolders. I have the letters A - O in rows 1 - 15 of the Excel spreadsheet but it is not creating those subfolders in RESERVES.

    Jim

+ 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