Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple Default Save Locations

Status
Not open for further replies.

shavon

Programmer
Jun 18, 2001
102
CA
Good day:

Is it possible to have multiple default save locations based on the template that I am using? I have a bunch of templates that I use for my job as a teacher. Each document needs to be saved at a different location on the drive which can sometimes be multiple folders deep. I just want to have a way of telling each template where to go so that I don't have to drill down so many levels.

Thank you...
 
I suppose you could put code in the OnOpen or OnLoad (whichever it is for Word - assuming you're talking about Word) event to change the default save-as location for the particular document, though I can't be sure... never tried.

Try something like this search to find out.
 
In one of my Excel timesheet templates I have this code (in the 'ThisWorkbook' section):
Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

  If Template Then
    SaveAsUI = False
    Cancel = True
    Application.EnableEvents = False
    Dim FileSaveName As Variant
      FileSaveName = Application.GetSaveAsFilename("D:\PROD\My Documents\Timesheets\" & Format(Date, "yyyy-mm-dd") & "_TSP" & ".xls")
      If FileSaveName <> VBA.vbFalse Then
        ActiveWorkbook.SaveAs Filename:=FileSaveName
      End If
    Template = False
    Application.EnableEvents = True
  End If

End Sub
If you look at the 'FileSaveName' variable, you will see that I point it to a specific directory and even use today's date as part of the file name. This may not be the best or easiest method, but if you customize this code for each of your templates, it should work.

The code will look a little different if you are using a Word or PowerPoint template, but the concept is the same.
 
Hi jges:

Thank you for pointing me in the right direction.

I found this code that is placed into Class1.
How do I get it to run when the save button is pressed please?

Thank you,

Public WithEvents App As Word.Application

Private Sub App_DocumentBeforePrint(ByVal Doc As Document, Cancel As Boolean)

MsgBox ("BEFORE PRINT TEST")

End Sub
 
Private Sub App_DocumentBeforeSave(Doc As Document, SaveAsUI As Boolean, Cancel As Boolean)
MsgBox ("BEFORE SAVE TEST")
End Sub

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thank you PHV:

I made a mistake. I meant to put "App_DocumentBeforeSave".

My real question is how do I get the code to run when I save? The code does not fire at all. I have not done this vb stuff in years. I have to somehow instantiate the class1 module, but I don't know how.
 
Straight from the VBA help:
Code:
Dim X As New EventClassModule
Sub Register_Event_Handler()
    Set X.App = Word.Application
End Sub

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
The code I posted lives in the 'Workbook' object (not its own class) which exposes certain events (save, open, etc). In my example the code is in the 'BeforeSave' event.

I rarely use Word, but I'm willing to bet it has a 'Document' object (or similar) that exposes similar events.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top