+ Reply to Thread
Results 1 to 9 of 9

VBA: MkDir Compile Error??

  1. #1
    Registered User
    Join Date
    11-27-2012
    Location
    France
    MS-Off Ver
    Excel 2007
    Posts
    65

    VBA: MkDir Compile Error??

    Hi,

    I am trying to create a directory if it doesn't exist already! Somehow, I'm not getting it done and I have no idea why.

    The error is: Compile Error - Expected Function or Variable

    The code is shown below:


    Please Login or Register  to view this content.
    I don't understand the bug in this. Can somebody suggest me a correction? It'd help alot!

    Thanks in advance.

    Sanjeev

  2. #2
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: VBA: MkDir Compile Error??

    it ought to be
    Please Login or Register  to view this content.
    but I don't reckon that's the cause-do have variables or modules called Len, dir or mkdir?
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  3. #3
    Registered User
    Join Date
    11-27-2012
    Location
    France
    MS-Off Ver
    Excel 2007
    Posts
    65

    Re: VBA: MkDir Compile Error??

    Thanks JosephP for your reply.

    Infact it doesn't accept the syntax for Mkdir as you suggested! It does accept MkDir (Path & "\Restitue")

    No, none of the variables are called Len, dir or mkdir in the entire code.

    I searched for this error, it says the MkDir expects a string which it is not getting to create the directory. Now whats that bug? I have no idea

  4. #4
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: VBA: MkDir Compile Error??

    are you actually using vba and not say vb.net? the vba compiler should not leave the code exactly as you posted it originally

    this code compiles and runs without error in vba
    Please Login or Register  to view this content.
    Last edited by JosephP; 03-28-2013 at 05:26 AM.

  5. #5
    Registered User
    Join Date
    11-27-2012
    Location
    France
    MS-Off Ver
    Excel 2007
    Posts
    65

    Re: VBA: MkDir Compile Error??

    The VB in my computer is Microsoft Visual Basic 6.5 (1987-2006), Version 1020.

    MS Office version is 2007, however the VB is 2006, so is that the incompatibility?

    I'll try to install a newer version of VB if that would work!

  6. #6
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: VBA: MkDir Compile Error??

    no if you're using vba in excel that code ought to work as it's written. if it doesn't there's something else in the workbook stopping it

  7. #7
    Registered User
    Join Date
    11-27-2012
    Location
    France
    MS-Off Ver
    Excel 2007
    Posts
    65

    Re: VBA: MkDir Compile Error??

    Well, in that case I prefer to show you the entire code and you may find the bug!

    This code merges data from several workbooks contained in a subfolder. It initially opens a workbook and copies the data from workbooks and then save the merged workbook with the subfolder name. It loops through all the subfolders in a folder and saves each time the merged workbook with the subfolder name.

    I'm trying to put all the merged workbooks in a new directory inside the main folder, thats where it is not accepting the "MkDir" part!

    Here is the code:

    Please Login or Register  to view this content.
    Thanks in advance! I hope it would work out!

    Sanjeev

  8. #8
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: VBA: MkDir Compile Error??

    I need to see the workbook please. you can remove any data

  9. #9
    Registered User
    Join Date
    11-27-2012
    Location
    France
    MS-Off Ver
    Excel 2007
    Posts
    65

    Re: VBA: MkDir Compile Error??

    well, I don't know how, the code resumed working itself after showing error a few times this morning. I removed the brackets as you said and its working now, while it didn't work with the same yesterday!

    Thanks again for your help.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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