I have a template which automatically generates the dates for the
following week (sunday to saturday) for any new document based on the
template. It also sets the filename to be those dates.
The only problem is that whenever i go to save the document it tries
to save it in some odd temporary folder. How can i specify what
directory to save the document to. The only things i can find about it
seem to be how to make a file automatically save to a directory, which
i don't think is necessary; i just want to be able to change the
folder that is shown when you go File>Save.

Thanks

Re: Specify directory to save to by Doug

Doug
Thu Jun 19 03:31:30 PDT 2008

Not sure how you are setting the filename, but include the path in it.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"chris_huh" <chris.huh@gmail.com> wrote in message
news:2527ba07-db6b-45e6-b0d0-dbbe87f34535@z66g2000hsc.googlegroups.com...
>I have a template which automatically generates the dates for the
> following week (sunday to saturday) for any new document based on the
> template. It also sets the filename to be those dates.
> The only problem is that whenever i go to save the document it tries
> to save it in some odd temporary folder. How can i specify what
> directory to save the document to. The only things i can find about it
> seem to be how to make a file automatically save to a directory, which
> i don't think is necessary; i just want to be able to change the
> folder that is shown when you go File>Save.
>
> Thanks



Re: Specify directory to save to by chris_huh

chris_huh
Thu Jun 19 03:44:58 PDT 2008

On Jun 19, 11:31=A0am, "Doug Robbins - Word MVP"
<d...@REMOVECAPSmvps.org> wrote:
> Not sure how you are setting the filename, but include the path in it.
>
> --
> Hope this helps.
>
> Please reply to the newsgroup unless you wish to avail yourself of my
> services on a paid consulting basis.
>
> Doug Robbins - Word MVP
>
> "chris_huh" <chris....@gmail.com> wrote in message
>
> news:2527ba07-db6b-45e6-b0d0-dbbe87f34535@z66g2000hsc.googlegroups.com...
>
>
>
> >I have a template which automatically generates the dates for the
> > following week (sunday to saturday) for any new document based on the
> > template. It also sets the filename to be those dates.
> > The only problem is that whenever i go to save the document it tries
> > to save it in some odd temporary folder. How can i specify what
> > directory to save the document to. The only things i can find about it
> > seem to be how to make a file automatically save to a directory, which
> > i don't think is necessary; i just want to be able to change the
> > folder that is shown when you go File>Save.
>
> > Thanks- Hide quoted text -
>
> - Show quoted text -

The code that i have is:

Function WeekStart() As Date
Dim wday As Byte
wday =3D Weekday(Date)
Select Case wday
Case 1
WeekStart =3D Date
Case 2
WeekStart =3D Date - 1
Case 3
WeekStart =3D Date - 2
Case 4
WeekStart =3D Date - 3
Case 5
WeekStart =3D Date - 4
Case 6
WeekStart =3D Date - 5
Case 7
WeekStart =3D Date - 6
End Select
End Function

Sub AutoNew()
Selection.GoTo What:=3DwdGoToBookmark, Name:=3D"DateRange"
Selection.InsertBefore Format(WeekStart() + 7, "dddd, d MMMM")
Selection.InsertAfter " to "
Selection.InsertAfter Format(WeekStart() + 13, "dddd, d MMMM yyyy")

Sunday =3D Format(WeekStart() + 7, "d")
Saturday =3D Format(WeekStart() + 13, "d MMM yy")

FileTitle =3D Sunday + " to " + Saturday

With Dialogs(wdDialogFileSummaryInfo)
.Title =3D FileTitle
.Execute
End With
End Sub

The last few lines deal with the filename. If i include the directory
structure with the filename (ie FileTitle =3D "C:\" + Sunday + " to " +
Sunday) it doesnt work and it just tries to have that as the filename.

Re: Specify directory to save to by JeanGuyMarcil

JeanGuyMarcil
Thu Jun 19 05:15:02 PDT 2008

"chris_huh" wrote:

> On Jun 19, 11:31 am, "Doug Robbins - Word MVP"
> <d...@REMOVECAPSmvps.org> wrote:
> > Not sure how you are setting the filename, but include the path in it.
> >
> > --
> > Hope this helps.
> >
> > Please reply to the newsgroup unless you wish to avail yourself of my
> > services on a paid consulting basis.
> >
> > Doug Robbins - Word MVP
> >
> > "chris_huh" <chris....@gmail.com> wrote in message
> >
> > news:2527ba07-db6b-45e6-b0d0-dbbe87f34535@z66g2000hsc.googlegroups.com...
> >
> >
> >
> > >I have a template which automatically generates the dates for the
> > > following week (sunday to saturday) for any new document based on the
> > > template. It also sets the filename to be those dates.
> > > The only problem is that whenever i go to save the document it tries
> > > to save it in some odd temporary folder. How can i specify what
> > > directory to save the document to. The only things i can find about it
> > > seem to be how to make a file automatically save to a directory, which
> > > i don't think is necessary; i just want to be able to change the
> > > folder that is shown when you go File>Save.
> >
> > > Thanks- Hide quoted text -
> >
> > - Show quoted text -
>
> The code that i have is:
>
> Function WeekStart() As Date
> Dim wday As Byte
> wday = Weekday(Date)
> Select Case wday
> Case 1
> WeekStart = Date
> Case 2
> WeekStart = Date - 1
> Case 3
> WeekStart = Date - 2
> Case 4
> WeekStart = Date - 3
> Case 5
> WeekStart = Date - 4
> Case 6
> WeekStart = Date - 5
> Case 7
> WeekStart = Date - 6
> End Select
> End Function
>
> Sub AutoNew()
> Selection.GoTo What:=wdGoToBookmark, Name:="DateRange"
> Selection.InsertBefore Format(WeekStart() + 7, "dddd, d MMMM")
> Selection.InsertAfter " to "
> Selection.InsertAfter Format(WeekStart() + 13, "dddd, d MMMM yyyy")
>
> Sunday = Format(WeekStart() + 7, "d")
> Saturday = Format(WeekStart() + 13, "d MMM yy")
>
> FileTitle = Sunday + " to " + Saturday
>
> With Dialogs(wdDialogFileSummaryInfo)
> .Title = FileTitle
> .Execute
> End With
> End Sub
>
> The last few lines deal with the filename. If i include the directory
> structure with the filename (ie FileTitle = "C:\" + Sunday + " to " +
> Sunday) it doesnt work and it just tries to have that as the filename.

Why don't you replace

With Dialogs(wdDialogFileSummaryInfo)
.Title = FileTitle
.Execute
End With

with

ActiveDocument.SaveAs "C:\myPath\" & FileTitle

???

By the way, the prefered way of concatenating elements in VBA is using the
ampersand "&" and not the plus sign "+".

Run this code to see the difference:

Dim str1 As String
Dim lng1 As Long

str1 = "10"
lng1 = 5

MsgBox str1 + lng1
MsgBox str1 & lng1


Jay Freedman has a good description of what is going on here:

http://groups.google.com/group/microsoft.public.word.vba.beginners/browse_thread/thread/e43d727d52f5b476/f750ba3a8f5d1b1f?hl=en&lnk=st&q=#f750ba3a8f5d1b1f

Re: Specify directory to save to by chris_huh

chris_huh
Thu Jun 19 05:44:05 PDT 2008

On Jun 19, 1:15=A0pm, Jean-Guy Marcil
<JeanGuyMar...@discussions.microsoft.com> wrote:
> "chris_huh" wrote:
> > On Jun 19, 11:31 am, "Doug Robbins - Word MVP"
> > <d...@REMOVECAPSmvps.org> wrote:
> > > Not sure how you are setting the filename, but include the path in it=
.
>
> > > --
> > > Hope this helps.
>
> > > Please reply to the newsgroup unless you wish to avail yourself of my
> > > services on a paid consulting basis.
>
> > > Doug Robbins - Word MVP
>
> > > "chris_huh" <chris....@gmail.com> wrote in message
>
> > >news:2527ba07-db6b-45e6-b0d0-dbbe87f34535@z66g2000hsc.googlegroups.com=
...
>
> > > >I have a template which automatically generates the dates for the
> > > > following week (sunday to saturday) for any new document based on t=
he
> > > > template. It also sets the filename to be those dates.
> > > > The only problem is that whenever i go to save the document it trie=
s
> > > > to save it in some odd temporary folder. How can i specify what
> > > > directory to save the document to. The only things i can find about=
it
> > > > seem to be how to make a file automatically save to a directory, wh=
ich
> > > > i don't think is necessary; i just want to be able to change the
> > > > folder that is shown when you go File>Save.
>
> > > > Thanks- Hide quoted text -
>
> > > - Show quoted text -
>
> > The code that i have is:
>
> > Function WeekStart() As Date
> > =A0Dim wday As Byte
> > =A0wday =3D Weekday(Date)
> > =A0Select Case wday
> > =A0 Case 1
> > =A0 =A0WeekStart =3D Date
> > =A0 Case 2
> > =A0 =A0WeekStart =3D Date - 1
> > =A0 Case 3
> > =A0 =A0WeekStart =3D Date - 2
> > =A0 Case 4
> > =A0 =A0WeekStart =3D Date - 3
> > =A0 Case 5
> > =A0 =A0WeekStart =3D Date - 4
> > =A0 Case 6
> > =A0 =A0WeekStart =3D Date - 5
> > =A0 Case 7
> > =A0 =A0WeekStart =3D Date - 6
> > =A0 End Select
> > End Function
>
> > Sub AutoNew()
> > Selection.GoTo What:=3DwdGoToBookmark, Name:=3D"DateRange"
> > Selection.InsertBefore Format(WeekStart() + 7, "dddd, d MMMM")
> > Selection.InsertAfter " to "
> > Selection.InsertAfter Format(WeekStart() + 13, "dddd, d MMMM yyyy")
>
> > Sunday =3D Format(WeekStart() + 7, "d")
> > Saturday =3D Format(WeekStart() + 13, "d MMM yy")
>
> > FileTitle =3D Sunday + " to " + Saturday
>
> > With Dialogs(wdDialogFileSummaryInfo)
> > =A0 =A0 .Title =3D FileTitle
> > =A0 =A0 =A0.Execute
> > End With
> > End Sub
>
> > The last few lines deal with the filename. If i include the directory
> > structure with the filename (ie FileTitle =3D "C:\" + Sunday + " to " +
> > Sunday) it doesnt work and it just tries to have that as the filename.
>
> Why don't you replace
>
> =A0 =A0With Dialogs(wdDialogFileSummaryInfo)
> =A0 =A0 =A0 .Title =3D FileTitle
> =A0 =A0 =A0 .Execute
> =A0 =A0End With
>
> with
>
> ActiveDocument.SaveAs "C:\myPath\" & FileTitle
>
> ???
>
> By the way, the prefered way of concatenating elements in VBA is using th=
e
> ampersand "&" and not the plus sign "+".
>
> Run this code to see the difference:
>
> Dim str1 As String
> Dim lng1 As Long
>
> str1 =3D "10"
> lng1 =3D 5
>
> MsgBox str1 + lng1
> MsgBox str1 & lng1
>
> Jay Freedman has a good description of what is going on here:
>
> http://groups.google.com/group/microsoft.public.word.vba.beginners/br...-=
Hide quoted text -
>
> - Show quoted text -

Ah that works better, thanks. I have got it to go into the correct
directory now, but it automatically saves it as soon as the document
is opened. I guess this is because it is in the AutoNew bit. I don't
know a great deal about macros and vb (hence the + not &). Where would
i put this so that you still have to actively save the file, and
hopefully have the option the change the title/directory (ie through
the save file browse window).

Thanks

Re: Specify directory to save to by JeanGuyMarcil

JeanGuyMarcil
Thu Jun 19 07:53:01 PDT 2008

"chris_huh" wrote:

> Ah that works better, thanks. I have got it to go into the correct
> directory now, but it automatically saves it as soon as the document
> is opened. I guess this is because it is in the AutoNew bit. I don't
> know a great deal about macros and vb (hence the + not &). Where would
> i put this so that you still have to actively save the file, and
> hopefully have the option the change the title/directory (ie through
> the save file browse window).
>

If you want to give the user the option of over-riding your suggestions, use
the dialogue but in order to point to a specific folder, you need a bit more
code.
Here is what you vcould do:

'Decalre this variable with your other variables
Dim sOrgPath As String
Dim sPath As String

'When you get to the saving part, use something like:
'Remember the original path
sOrgPath = Options.DefaultFilePath(wdDocumentsPath)
'Set the new path you wish to use
ChangeFileOpenDirectory ("C:\")
With Dialogs(wdDialogFileSaveAs)
.Name = FileTitle
'If the user pressed "Save"
If .Display = -1 Then
'Execute the dialog
.Execute
End If
'Restore original path
ChangeFileOpenDirectory sOrgPath

End With