+ Reply to Thread
Results 1 to 6 of 6

"ActiveWorkbook.SaveAs" Not Saving?

  1. #1
    Registered User
    Join Date
    11-16-2012
    Location
    Rhode Island, USA
    MS-Off Ver
    Excel 2010
    Posts
    11

    "ActiveWorkbook.SaveAs" Not Saving?

    I'm new at macros so please bare with me.

    The below code should save a version of the file in CSV format with a name equal to a cell value.
    Sometimes it works, sometimes it doesn't. I added what I think is a check to see if the file exists. The macro acts as if the file is there and gives me my msgbox. When checking the folder in explorer, it doesn't show. When I try the macro again, Excel even asks if a want to replace the existing file. Even though the file doesn't show. What is happening?

    Sub ExportCSCSV()
    '
    ' ExportCSCSV Macro
    '
    Dim MyFile As String
    MyFile = Range("A3").Value & ".csv"

    Dim Loc As String
    Loc = "\\JMAS\Share\CSV_FILES\Cost Sheet\" & MyFile

    ChDir "\\JMAS\Share\CSV_FILES\Cost Sheet"
    ActiveWorkbook.SaveAs Filename:=MyFile, _
    FileFormat:=xlCSV, CreateBackup:=False

    If Loc <> "" Then MsgBox (MyFile & " has been successfully saved to \\JMAS\Share\CSV_FILES\Cost Sheet")


    ActiveWorkbook.Close



    '
    End Sub
    Last edited by enidnunez; 11-27-2012 at 02:42 PM.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: "ActiveWorkbook.SaveAs" Not Saving?

    I know you are changing directory but you should also specify the path as well as the filename when saving.
    If posting code please use code tags, see here.

  3. #3
    Valued Forum Contributor
    Join Date
    11-02-2012
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    564

    Re: "ActiveWorkbook.SaveAs" Not Saving?

    Can you cancel the msgbox when excel asks you to replace the file and see if that file path is matching to the folder you specified? You can use =Cell("filename") function in any of the cell in that workbook and see.

  4. #4
    Valued Forum Contributor
    Join Date
    11-02-2012
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    564

    Re: "ActiveWorkbook.SaveAs" Not Saving?

    Instead of Myfile in your save as, use Loc

  5. #5
    Registered User
    Join Date
    11-16-2012
    Location
    Rhode Island, USA
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: "ActiveWorkbook.SaveAs" Not Saving?

    Exactly what I ended up doing. It's a beautiful thing.
    >>Smiles<<
    Thanks!

  6. #6
    Valued Forum Contributor
    Join Date
    11-02-2012
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    564

    Re: "ActiveWorkbook.SaveAs" Not Saving?

    Glad I could help. Please update the thread as [solved] if its been answered.

+ 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