+ Reply to Thread
Results 1 to 7 of 7

Macro not saving file to correct path

  1. #1
    Registered User
    Join Date
    11-01-2012
    Location
    Denver, Colorado
    MS-Off Ver
    Excel 2010
    Posts
    8

    Macro not saving file to correct path

    Hello,
    I have a macro that I run on a file each morning that formats it, saves it to my network drive(I, emails a copy, then closes. But I am unable to get it to save to the correct folder in the network drive. It will save in the I: but not in a subfolder. If I try to save to my desktop, it does not save it.
    This is the section of the macro that does the saving:
    Range("A1").Select
    Path = "I:"
    fname = Format(Date, "mm-dd-yyyy") & "__WPOT_IP_Report"
    ActiveWorkbook.SaveAs Filename:=Path & fname, FileFormat:= _
    xlOpenXMLWorkbook, CreateBackup:=False

    When I enter the path to the folder(daily report) I want to save, it saves it to the I drive with the name of the folder at the beginning of the file name. Example: "Daily Report_10-03-2013_WPOT_IP_Report". I also tried saving to my desktop "C:\Users\pricer\Desktop" but it just dissapears.

    Can you tell from what I have in my macro what might be causing this?

  2. #2
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Macro not saving file to correct path

    You might need to add a "\" between the path and file name.

    This also probably won't work if there are any imbedded spaces in any file or folder name.
    To correct the imbedded space problem:
    Please Login or Register  to view this content.
    Last edited by LJMetzger; 10-08-2013 at 04:34 PM. Reason: Added ampersand before fname - previously omitted in error

  3. #3
    Registered User
    Join Date
    11-01-2012
    Location
    Denver, Colorado
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Macro not saving file to correct path

    Thanks for the tip.
    When I tried what you have ( I think I did it right), the line of code turns red and I get "Compile Error: Expected: End of Statement and the word "Format" is highlighted.
    Here is what I put in:
    sPathAndFileName = """" & "I:\Patient_Admissions" & "\" Format(Date, "mm-dd-yyyy") & "__WPOT_IP_Report" & """"
    ActiveWorkbook.SaveAs Filename:=sPathAndFileName, FileFormat:= _
    xlOpenXMLWorkbook, CreateBackup:=False

  4. #4
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Macro not saving file to correct path

    Sorry, my fault. There should be an ampersand '&' after the "\"

    You had:
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    11-01-2012
    Location
    Denver, Colorado
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Macro not saving file to correct path

    That helped! But now it's not saving as an excel file. Sorry for not getting this, but I really appreciate your help. Here is what I have.

    sPathAndFileName = """" & "I:\Patient_Admissions" & "\" & Format(Date, "mm-dd-yyyy") & "__WPOT_IP_Report" & """"
    ActiveWorkbook.SaveAs Filename:=sPathAndFileName, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False

  6. #6
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Macro not saving file to correct path

    I'm no expert on Excel File formats, but your problem is probably:

    FileFormat:=xlOpenXMLWorkbook

    I would try either 'xlWorkbookDefault' or 'xlWorkbookNormal' which will probably save
    the workbook for you in Excel 2010 format.

    I use Excel 2003 and use:
    Please Login or Register  to view this content.
    For a more complete list see:
    http://msdn.microsoft.com/en-us/libr...ileformat.aspx

  7. #7
    Registered User
    Join Date
    11-01-2012
    Location
    Denver, Colorado
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Macro not saving file to correct path

    Well, the last bit of advice would not work for me. But I went back to your first reply and tested it again with the "\" and it worked. I think I was trying to combine that bit of advice with the other steps you said I might need and it would not work. Now it all seems to be working fine. Thanks 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)

Similar Threads

  1. Macro saving file path to xlsx but can i specify what sheet
    By Badvgood in forum Access Programming / VBA / Macros
    Replies: 1
    Last Post: 12-05-2011, 04:47 PM
  2. Problem saving to correct file path
    By pixifaery in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-27-2010, 09:58 AM
  3. Saving file to same path as open file
    By Glio in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-19-2007, 04:57 AM
  4. Path for File Saving Defined by USER
    By crapmind in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-21-2007, 09:58 AM
  5. Saving a file to a different path
    By SVTman74 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-26-2005, 04:05 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