CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: save as code

  1. #1
    Join Date
    Dec 2010
    Posts
    2

    save as code

    Good morning,

    I am looking for a code that will save the file from the contents of A1 and change the format of the excel spreadsheet to comma delimited.

    My problem is that the contents of A1 is a date and i think i am getting an error because the date contains forward slashes (00/00/000) and i believe that that is a invalid character to have as a file name.

    What i am looking for is to take the contents of A1 which will be in the format of 00/00/0000 but save it in the filename as 00_00_0000.

    I currently have this simple code, if any one can tweak it to achieve the results i am looking for i would greatly appreciate it.

    Public Sub SaveAsA1()
    ThisFile = Range("A1").Value
    ActiveWorkbook.SaveAs Filename:=ThisFile, FileFormat:=xlCSV

    End Sub

  2. #2
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: save as code

    I see two options to achive what you want:

    1) Format cell A1 with a custom date format like MM\_DD\_YYYY and change your code line to determine the file name to this:

    Code:
    ThisFile = Range("A1").Text
    This will access the formatted date value of the cell instead of the raw value.

    2) If you don't want to change the appearance of the date on the spreadsheet, format the date in your VBA code:

    Code:
    ThisFile = Format(Range("A1").Value, "mm_dd_yyyy")
    HTH

    Although it wasn't too much pain with the tiny code snippet in your post above, please use code tags next time you post code. This will make the code much more readable.

    Ah, and... Welcome to CodeGuru!
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  3. #3
    Join Date
    Dec 2010
    Posts
    2

    Re: save as code

    thanks, it work succesfully

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured