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