+ Reply to Thread
Results 1 to 10 of 10

Path name invalid when trying to save a workbook - VBA

  1. #1
    Registered User
    Join Date
    07-17-2013
    Location
    Isle of Man
    MS-Off Ver
    Excel 2003
    Posts
    5

    Path name invalid when trying to save a workbook - VBA

    Hi Guys,

    I'm currently trying to write a macro to save an excel file under a path name (folder) but i'm not having any luck! hoping you guys can help!!

    Below is my macro so far...

    Sub SaveJournal()
    Dim Path As String
    Dim FileName1 As String
    Dim FileName2 As String
    Path = "S:\accounts\TREASURY\VISIN Journal Import\China Posted Journals\"
    FileName1 = Range("C8")
    FileName2 = Range("C11")
    ActiveWorkbook.SaveAs Filename:=Path & FileName1 & " -" & FileName2 & ".xls", FileFormat:=xlNormal
    End Sub

    The above VBA DOES work! but under this path (folder) there are sub folders which i am wanting the workbook to save to depending on th value in cell C8! just in case that confuses things.. the following folder S:\accounts\TREASURY\VISIN Journal Import\China Posted Journals\ has 3 folders within named JCA, SCA and FNE. and i'm wanting the workbook to save to the above path and also the sub folder which will be in C8 (c8 for example will have JCA) so i want the end product to save under the path S:\accounts\TREASURY\VISIN Journal Import\China Posted Journals\JCA but i'm having no luck trying to do this!

    Can anyone help?

    I look forward to hearing your repsonses!

    Cheers
    Jamie

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,895

    Re: Path name invalid when trying to save a workbook - VBA

    Does it help to have C8 value changed to JCA\. I think the backslash is needed either in C8 or in your code.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Registered User
    Join Date
    07-17-2013
    Location
    Isle of Man
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Path name invalid when trying to save a workbook - VBA

    Unfortunately not.. I should of stated above that i am afte something to add at the end of the 'path' name to look at cell C8 to determine which folder it needs to be saved in.
    so far i have
    Path = "S:\accounts\TREASURY\VISIN Journal Import\China Posted Journals\"
    but i need to add on the end of this something along the lines of = Range ("C8") but it's not working.

  4. #4
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,895

    Re: Path name invalid when trying to save a workbook - VBA

    Oh, you need to get the value of each of the ranges.

    Your code would be:

    Please Login or Register  to view this content.
    BTW: You should be using code tags when you post. This is in the forum rules.Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

  5. #5
    Registered User
    Join Date
    07-17-2013
    Location
    Isle of Man
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Path name invalid when trying to save a workbook - VBA

    Sorry Alan,

    I think my explanations may not be very clear.

    Where you have put the filenames above, These are woking fine for me but the path name itself isn't working

    my final outcome of the save as feature i want should be as 'JCA (filename1) - 1256(filename2)' and i want this under the path name/ folder

    HTML Code: 
    and the sub folder which is in

    HTML Code: 
    This is the bit i'm having problems with putting on the end of my file path

    Sory about the 'rules'. i'll make sur ei read them now

    Jamie

  6. #6
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,895

    Re: Path name invalid when trying to save a workbook - VBA

    Currently when you run the code, where are the files being saved. I am now confused. I thought I understood your issue, but now I am fuzzy.

  7. #7
    Registered User
    Join Date
    07-17-2013
    Location
    Isle of Man
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Path name invalid when trying to save a workbook - VBA

    haha so sorry about this!

    I shall start again.

    When i run the below code

    HTML Code: 
    It will save it into the folder named 'China Posted Journals' as JCA - 1256 (C8 - C11)

    but.. What i'm wantng to do is amend the path name (below) to add in cell (C8) 'JCA' at th end as this is a folder within the 'China Posted Journals'

    HTML Code: 
    my attempt of this was

    HTML Code: 
    But this didn't work!!

    I hope this helped explain.. slightly

  8. #8
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,895

    Re: Path name invalid when trying to save a workbook - VBA

    ah! I think I got it now.

    [code]
    Sub SaveJournal()
    Dim Path As String
    Dim FileName1 As String
    Dim FileName2 As String
    Path = "S:\accounts\TREASURY\VISIN Journal Import\China Posted Journals\"
    FileName1 = Range("C8")
    FileName2 = Range("C11")
    Path = Path & FileName1 & "\"
    ActiveWorkbook.SaveAs Filename:=Path & " -" & FileName2 & ".xls", FileFormat:=xlNormal
    End Sub

  9. #9
    Registered User
    Join Date
    07-17-2013
    Location
    Isle of Man
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Path name invalid when trying to save a workbook - VBA

    IT WORKS!!!!

    thank you so so much!!

  10. #10
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,895

    Re: Path name invalid when trying to save a workbook - VBA

    Excellent. Please mark your thread solved

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Save As path
    By graiggoriz in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 07-16-2013, 07:31 AM
  2. Replies: 5
    Last Post: 03-21-2013, 07:34 AM
  3. [SOLVED] Save As Dialog Box - Default Path and File Name, User Selects Sub Folder from Default Path
    By christenprochaska in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-12-2012, 05:17 PM
  4. [SOLVED] Macro to get worksheets to save to new workbook with OPEN workbooks .PATH & " " as name.
    By NicksDad in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-03-2012, 08:07 PM
  5. Save Workbook using name and path in a cell
    By adinic in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-11-2007, 01:27 PM

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