View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.misc
GS[_2_] GS[_2_] is offline
external usenet poster
 
Posts: 3,514
Default problems getting this macro to work

Here's my actual procedure that I made your sample from...

Sub TimeStampFile(Optional Wkb As Workbook, Optional sSavePath$)
' Saves a copy of Wkb with '-name-time' stamp
Dim sNameStamp$, vFileInfo

If Wkb Is Nothing Then Set Wkb = ActiveWorkbook
vFileInfo = Split(Wkb.FullName, ".")

If sSavePath < "" Then
If Right(sSavePath, 1) < "\" Then sSavePath = sSavePath & "\"
vFileInfo(0) = sSavePath
End If
sNameStamp = "-" & Environ("username") & "-"

Wkb.SaveCopyAs Join(vFileInfo, sNameStamp & Now())
End Sub

...which puts the login user in sNameStamp. Here's examples of how I
might use it...

Sub Test_TimeStampFile()
'To save a copy of ActiveWorkbook to its .Path
Call TimeStampFile

'To save a copy of ActiveWorkbook to a different path
Call TimeStampFile(, "C:\Users\Ditchy\Work Related\")

'To save a copy of a specified Workbook to its .Path
Call TimeStampFile(ThisWorkbook) '//or Workbooks("?.?")

'To save a copy of a specified Workbook to a different path
Call TimeStampFile(ThisWorkbook, "C:\Users\Ditchy\Work Related\")
End Sub

So in your case, if you want the file copied to 2 different locations
then you need to call TimeStampFile twice. In your case you could store
the path to your user profile folder in a constant for convenience...

In a declarations section of the/any standard module:

Public Const gsMyWorkDocs$ = "C:\Users\Ditchy\Work Related\"

...where you can replace my "gs" prefix with your own if you use such
naming convention for indicating [scope]datatype of your variables.
(The g represents 'global' scope, the s represents 'string' type)

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion