Log in

View Full Version : Excel VB Script adjust


Pajoooo
May 20, 2010, 04:09 PM
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("Desktop") & Application.PathSeparator & MyDate & "_" & "dan" & "_"
parm1 = DTAdress & "123456.xls"

Thanks

JBeaucaire
May 20, 2010, 09:19 PM
Wouldn't that just be:

Dim DTAddress As String

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

Pajoooo
May 22, 2010, 04:21 AM
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

JBeaucaire
May 23, 2010, 07:20 AM
Use this:

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

Pajoooo
May 23, 2010, 12:37 PM
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.

JBeaucaire
May 24, 2010, 02:12 AM
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

Pajoooo
May 24, 2010, 03:20 AM
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.

JBeaucaire
May 24, 2010, 09:02 AM
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.