Syntax and compile error.

  • Thread starter Thread starter Jim15
  • Start date Start date
J

Jim15

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
 
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" <[email protected]>
wrote in message
news:[email protected]...
 
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
 
Dim Cou As Long: Dim foldersys As String: Dim filesys As Variant

But that's way too ugly for even me.
 
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
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top