+ Reply to Thread
Results 1 to 7 of 7

Use String Variables in File Path and create path if not existing

  1. #1
    Registered User
    Join Date
    07-26-2007
    Posts
    5

    Wink Use String Variables in File Path and create path if not existing

    Hi everyone! I am programming (or trying to!!) a Makro to make certain administrative tasks more efficient. Unfortunetly I am completly stuck:

    I have declared String Variables and used data from the workbook to define them:

    Dim SupplierCode As String
    Dim Year As String
    Dim ToyotaPlant As String
    Dim Month As String
    Dim Manifest As String

    Sheets("january").Select

    Range("B3").Select
    SupplierCode = ActiveCell

    Range("G3").Select
    ToyotaPlant = ActiveCell

    Range("J2").Select
    Month = ActiveCell

    Range("J3").Select
    Year = ActivCell

    Sheets("TPN").Select

    Range("L15").Select
    Manifest = ActiveCell

    Now I would like to save the file, using these variables in the File-Path:

    ActiveWorkbook.SaveAs Filename:="\\Brufs01\TRANSFER\TPN_Database\"Toyotaplant"\"Year"\"SupplierCode"\"Month"\"Manifest".xls", _
    FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
    ReadOnlyRecommended:=False, CreateBackup:=False

    This doesnt work, I think its only a syntax error but IMPOSSIBLE to make it work, aaargh

    Also if this path doesnt exist I would like excel to simply create and not make a fuss!!! Any help would be very very much appreciated!!

    Thanks alot in advance,

    Jan

  2. #2
    Forum Expert
    Join Date
    11-23-2005
    Location
    Rome
    MS-Off Ver
    Ms Office 2016
    Posts
    1,628
    Try to change the line:
    Please Login or Register  to view this content.
    with:
    Please Login or Register  to view this content.
    If you use " char in ".... " string you need do use double (""), for example: "...""....".

    Regards,
    Antonio

  3. #3
    Registered User
    Join Date
    07-26-2007
    Posts
    5

    Thanks

    Thanks antonio, this seems to work.....
    Unfortunetly I now get the error message: "Folder does not exist"
    I know this folder doesnt exist, I want Excel to create it while saving!! Do you (or anyone) know how I could do that?

  4. #4
    Forum Expert
    Join Date
    11-23-2005
    Location
    Rome
    MS-Off Ver
    Ms Office 2016
    Posts
    1,628
    You can use this code:
    Please Login or Register  to view this content.
    Regards,
    Antonio

  5. #5
    Registered User
    Join Date
    07-26-2007
    Posts
    5

    another little problem....

    Good Logic!

    Unfortunetly excel now tells me that

    Please Login or Register  to view this content.
    Is a "bad folder name"
    In particular it says that the line

    Please Login or Register  to view this content.
    Is problematic.... Do u maybe know why?

    Thanks for your help, mate!
    I really don't know why??

  6. #6
    Registered User
    Join Date
    07-26-2007
    Posts
    5
    I tried this:

    Please Login or Register  to view this content.
    And now he says that "Can't find file path"

    Well that's normal, silly program, because it should CREATE it????

  7. #7
    Registered User
    Join Date
    07-26-2007
    Posts
    5

    Thanks Alot Antonio!!

    I found my mistake: Because I was creating many Subfolders I had to make sure that every master folder existed before making a subfolder!!!

    Thank so much for you help! Have a good one!

+ 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