Saving to a specific file with a specific file name

C

Chr1551

Hello All,

I've been having a look around for an answer to my question and have tried
to piece together some VBA code for similar things but I'm a bit of an
amateur and can't get anything to work! So... I'm looking for some help!

What I want to do is basically create quotes and faxes from two separate
templates in Microsoft Word 2003 and then save them to a Quotes or a Faxes
folder. Can this be determined automatically depending on the template being
used? And can I set the filename automatically to be a fied from my document?

Is this possible? Any help would be much appreciated!

Many Thanks
 
J

Jean-Guy Marcil

Chr1551 said:
Hello All,

I've been having a look around for an answer to my question and have tried
to piece together some VBA code for similar things but I'm a bit of an
amateur and can't get anything to work! So... I'm looking for some help!

What I want to do is basically create quotes and faxes from two separate
templates in Microsoft Word 2003 and then save them to a Quotes or a Faxes
folder. Can this be determined automatically depending on the template being
used? And can I set the filename automatically to be a fied from my document?

Is this possible? Any help would be much appreciated!

Many Thanks

Yes, you can easily do that, but the only problem in your post is that it is
entirely unclear where the file name will come from. In the sample below, the
file name is lifted from a formfield called "Name". If you are working with
actual fields, it will be different...

This code displays the File Save As dialog with pre-entered information. It
assumes that one of the template names has the string "Quotes" in it.


Dim strPath As String
Dim strName As String

Const strQuotes As String = "Quotes"
Const strFaxes As String = "Faxes"

'Get template name...
If InStr(1, ActiveDocument.AttachedTemplate.Name, strQuotes) > 0 Then
strPath = "C:\" & strQuotes & Application.PathSeparator
Else
strPath = "C:\" & strFaxes & Application.PathSeparator
End If

'Get file name from document
strName = ActiveDocument.FormFields("Name").Result

'Set the new path you wish to use
ChangeFileOpenDirectory (strPath)
With Dialogs(wdDialogFileSaveAs)
.Name = strPath & strName & ".doc"
'If the user pressed "Save"
If .Display = -1 Then
'Execute the dialog
.Execute
End If
End With
 
J

Jean-Guy Marcil

Chr1551 said:
Hello All,

I've been having a look around for an answer to my question and have tried
to piece together some VBA code for similar things but I'm a bit of an
amateur and can't get anything to work! So... I'm looking for some help!

What I want to do is basically create quotes and faxes from two separate
templates in Microsoft Word 2003 and then save them to a Quotes or a Faxes
folder. Can this be determined automatically depending on the template being
used? And can I set the filename automatically to be a fied from my document?

Is this possible? Any help would be much appreciated!

Many Thanks

Ooops, I posted too fast... The code I postd in my previous post came from
two sources, and I did not adjust it correctly.
See the difference in the (wdDialogFileSaveAs).Name value assignment...


Dim strPath As String
Dim strName As String

Const strQuotes As String = "Quotes"
Const strFaxes As String = "Faxes"

'Get template name...
If InStr(1, ActiveDocument.AttachedTemplate.Name, strQuotes) > 0 Then
strPath = "C:\" & strQuotes & Application.PathSeparator
Else
strPath = "C:\" & strFaxes & Application.PathSeparator
End If

'Get file name from document
strName = ActiveDocument.FormFields("Name").Result

'Set the new path you wish to use
ChangeFileOpenDirectory (strPath)
With Dialogs(wdDialogFileSaveAs)
.Name = strName & ".doc"
'If the user pressed "Save"
If .Display = -1 Then
'Execute the dialog
.Execute
End If
End With
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top