+ Reply to Thread
Results 1 to 3 of 3

save a file using the date and the sheet name, in that order, to diff directory

  1. #1
    Registered User
    Join Date
    11-22-2012
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    26

    Question save a file using the date and the sheet name, in that order, to diff directory

    Hello everyone, thank you. Here is my question. I need to save a file using the date and the sheet name, in that order, like this:

    ActiveWorkbook.SaveAs Filename:=Format(Now(), "yymmdd") & ActiveSheet.Name, FileFormat _
    :=xlText, CreateBackup:=False

    This code works fine, except that it saves only to whatever directory you are already in - but I need to change directory.

    So I wrote:

    ChDir "\\Buffalo\website\AmazonPriceQtyUpdates"
    ActiveWorkbook.SaveAs Filename:=Format(Now(), "yymmdd") & ActiveSheet.Name, FileFormat _
    :=xlText, CreateBackup:=False

    The result is, the directory is not changed - it ignores that instruction and saves in the current directory I am in (My Document!)

    If I write the whole saveas filename routine then the instruction to save the date in front of the sheet name does not work anymore and I get a compile error. Like this:
    ChDir "\\Buffalo\website\AmazonPriceQtyUpdates"
    ActiveWorkbook.SaveAs Filename:= _
    "\\Buffalo\website\AmazonPriceQtyUpdates\Format(Now(), "yymmdd") & ActiveSheet.Name", FileFormat:= _
    xlText, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False _
    , CreateBackup:=False

    Please help - what am I missing?

  2. #2
    Registered User
    Join Date
    11-22-2012
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    26

    Re: save a file using the date and the sheet name, in that order, to diff directory

    I found the code somewhere else. If anyone is interested:

    'First establish that the file name is the date:
    Dim MyFile As String

    MyFile = Format(Now(), "yymmdd")


    'Then use MyFile to start the name of it. This way you can put the entire path in the save instruction, with the date first, without getting errors, and the file gets to be saved in the external server I want to use


    'Save file
    ChDir "\\Buffalo\website\AmazonPriceQtyUpdates"
    ActiveWorkbook.SaveAs Filename:="\\Buffalo\Website\AmazonPriceQtyUpdates\" & MyFile & ActiveSheet.Name, FileFormat _
    :=xlText, CreateBackup:=False

  3. #3
    Registered User
    Join Date
    11-22-2012
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    26

    Re: save a file using the date and the sheet name, in that order, to diff directory

    I found the code somewhere else. If anyone is interested:

    'First establish that the file name is the date:
    Dim MyFile As String

    MyFile = Format(Now(), "yymmdd")


    'Then use MyFile to start the name of it. This way you can put the entire path in the save instruction, with the date first, without getting errors, and the file gets to be saved in the external server I want to use


    'Save file
    ChDir "\\Buffalo\website\AmazonPriceQtyUpdates"
    ActiveWorkbook.SaveAs Filename:="\\Buffalo\Website\AmazonPriceQtyUpdates\" & MyFile & ActiveSheet.Name, FileFormat _
    :=xlText, CreateBackup:=False

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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