+ Reply to Thread
Results 1 to 15 of 15

Creating a file in a newly created folder.

  1. #1
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Washington DC
    MS-Off Ver
    Excel 2007
    Posts
    458

    Creating a file in a newly created folder.

    Hello everyone. Thanks to everyone who has helped me before. I would like to be able to create a file in a folder; which is created via input from the user. Below is the code that I am trying to use and it does not work. I am recieving a syntax error in Sub Macro1 for Filename. Any help would be greatly appreciated.

    Please Login or Register  to view this content.
    Essentially I am trying to add a workbook to the directory:

    Please Login or Register  to view this content.
    Last edited by AnthonyWB; 04-12-2010 at 03:01 PM.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Creating a file in a newly created folder.

    You're missing the line continuation character (the underscore) in the first line.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Washington DC
    MS-Off Ver
    Excel 2007
    Posts
    458

    Re: Creating a file in a newly created folder.

    Embarrassingly, I cannot see it?

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Creating a file in a newly created folder.

    Please Login or Register  to view this content.

  5. #5
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Creating a file in a newly created folder.

    Anthony

    In the CreateFolders macro I gave you yesterday, the DIM declarations should be INSIDE the macro, not above it.

    Check the original thread, I gave you a much more robust CreateFolders macro, too, one that would recover from existing files a little more elegantly.

    http://www.excelforum.com/excel-prog...g-folders.html
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  6. #6
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Washington DC
    MS-Off Ver
    Excel 2007
    Posts
    458

    Re: Creating a file in a newly created folder.

    shg and JBeaucaire, your help is apprecaited. I am still recieving an error "Save As Method Failed." , in the Macro 1. I put the DIM declarations Outside of the CreateFolders MACRO, so that they may be used in subsequent sub macros. Please see the code below. Your help is appreciated.

    Please Login or Register  to view this content.

  7. #7
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Creating a file in a newly created folder.

    Anthony, before the SaveAs, print the would-be path to the Immediate window and see if it's correct.

    More generally, spend some time reading http://www.cpearson.com/excel/Debug.htm

  8. #8
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Washington DC
    MS-Off Ver
    Excel 2007
    Posts
    458

    Re: Creating a file in a newly created folder.

    Thanks - I visited the website, and began using the Immediate window to see if the path is correct. I typed in

    Please Login or Register  to view this content.
    and recieved an invalid character error. The underscore preceeding the 157 is not the source as its removal does not eliminate the error. Any suggestions?

  9. #9
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Creating a file in a newly created folder.

    You're not entering dates with "/" in them are you? At the moment of the error, but your mouse over the fPath and the fDate variables...what are the exact values?

  10. #10
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Washington DC
    MS-Off Ver
    Excel 2007
    Posts
    458

    Re: Creating a file in a newly created folder.

    At the moment of error we have:

    fPath = "L:\"

    fDate = "12_31_2009" ; which is the date that was entered in the InputBox during the "run", so it is correct.

    No, I am not using "/" in the dates.

  11. #11
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Creating a file in a newly created folder.

    Well, I know this line of code in the immediate window won't work (give the invalid character message):

    Please Login or Register  to view this content.


    ...but this will:
    Please Login or Register  to view this content.

  12. #12
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Washington DC
    MS-Off Ver
    Excel 2007
    Posts
    458

    Re: Creating a file in a newly created folder.

    I am sorry I an not getting it. I am now being told a "constant expression is required"

    Please Login or Register  to view this content.

  13. #13
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Washington DC
    MS-Off Ver
    Excel 2007
    Posts
    458

    Re: Creating a file in a newly created folder.

    I am still wokring on this error. I using the immediate window to debug:

    Please Login or Register  to view this content.
    It appears to be the correct path. However in running the code I recieve a "Constant Expression Required" error. Are there problems with how I am declaring variables? fDate is not a function. So the value should be the same throughout each macro, likewise with fPath.

  14. #14
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Creating a file in a newly created folder.

    You can't do this:
    Please Login or Register  to view this content.
    The value of a constant is assigned at compile time, so there can't be any variables in its definition. It can include only literal values, or other constants previously defined in the same scope.

    sPath1 needs to be a variable.

  15. #15
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Washington DC
    MS-Off Ver
    Excel 2007
    Posts
    458

    Re: Creating a file in a newly created folder.

    I got it. Thank you. FYI - I am learning a tremendous amount on this forum.

    Please Login or Register  to view this content.

+ 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