Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Spreadsheets (https://www.askmehelpdesk.com/forumdisplay.php?f=395)
-   -   Excel VB Script adjust (https://www.askmehelpdesk.com/showthread.php?t=472050)

  • May 20, 2010, 04:09 PM
    Pajoooo
    Excel VB Script adjust
    I need to save file on c:\abcd\efgh\ijkl folder.

    Part of script that save file on Desktop:

    Dim DTAddress As String
    DTAddress = CreateObject("WScript.Shell").SpecialFolders("Desk top") & Application.PathSeparator & MyDate & "_" & "dan" & "_"
    parm1 = DTAdress & "123456.xls"

    Thanks
  • May 20, 2010, 09:19 PM
    JBeaucaire

    Wouldn't that just be:
    Code:

    Dim DTAddress As String

    DTAddress = "C:\abcd\efgh\ijkl\" & MyDate & "_dan_123456.xls"
    ActiveWorkbook.SaveAs DTAddress, xlNormal

  • May 22, 2010, 04:21 AM
    Pajoooo
    1 Attachment(s)
    That's it!


    Another request
    When I close the file first time, he saved as, for example, 22.05.2010_night_reviewarticle.xls. I need to each following closure of that file one copy kept on the Desktop and the name of the file does not change, regardless of the actual date and time
  • May 23, 2010, 07:20 AM
    JBeaucaire

    Use this:
    Code:

    Sub If_File_Exists()
    'Jerry Beaucaire  5/23/2010
    'Automatically save two copies of this workbook
    Dim oWSS      As Object
    Dim MyDesktop As String
    Dim MyDate As String
    Dim fPath    As String:    fPath = "C:\ReviewArticle\Archive\Night\"
    Dim fnString  As String:    fnString = "Night_ReviewArticle.xls"
    Application.DisplayAlerts = False

        Set oWSS = CreateObject("WScript.Shell")
            With oWSS
                MyDesktop = .SpecialFolders("Desktop") & Application.PathSeparator
            End With
        Set oWSS = Nothing

        MyDate = Format(Date, "DD.MM.YYYY_")
        ActiveWorkbook.SaveAs (fPath & MyDate & fnString), xlNormal
        ActiveWorkbook.SaveCopyAs (MyDesktop & fnString)

    End Sub

  • May 23, 2010, 12:37 PM
    Pajoooo
    This kept the file in two locations under the names I needed and tis is OK.
    Besides this I need that a saved file with one name forever preserved under this name, regardless of the opening under a different date.
  • May 24, 2010, 02:12 AM
    JBeaucaire

    The macro given should save the file in two places with two different strings:

    C:\ReviewArticle\Archive\Night\DD.MM.YYYY_Night_Re viewArticle.xls


    And then:

    Desktop\Night_ReviewArticle.xls
  • May 24, 2010, 03:20 AM
    Pajoooo
    Yes, it's so.

    I'll try to explain,

    Desktop\Night_ReviewArticle.xls is the working file, and C:\ReviewArticle\Archive\Night\DD.MM.YYYY_Night_Re viewArticle.xls is the archive file.

    Today is 24.05.2010.
    When I close Night.xls file I'll get two files:
    1. Night_ReviewArticle.xls on the Desktop
    2. 24.05.2010_Night_ReviewArticle.xls in C:\ReviewArticle\Archive\Night\

    When I, for example, 31.05.2010. Open this archive file (24.05.2010_Night_ReviewArticle.xls) for inspection and correction, after closing them, in the archives I have a new file 31.05.2010_Night_ReviewArticle.xls, and so the archive becomes unusable.

    I need to just first time archive file be saved as, for example, 24.05.2010_Night_ReviewArticle.xls and that any following closure of that archive file not change its name.
  • May 24, 2010, 09:02 AM
    JBeaucaire

    Well, first thought is that when you open old files, don't allow macros to run on those files for that session. IF you security is set to Medium, it should ask you if it's OK to run macros each time you open a file with macros in them, just say "no" when you're opening an already saved/archived file.

  • All times are GMT -7. The time now is 04:12 PM.