Re: Saving to a specific file with a specific file name



Well... I got things working with the M:\Quotes directory opening for saving
but when I added the code for naming the file it no longer works, while the
naming code works fine (if slowly)!! Strange! This is what I have:

Sub FileSaveAs()
Dim strName As String
On Error Resume Next
ChangeFileOpenDirectory "M:\Quotes\"
'Get file name from document table _
(First table, third row, second column)
strName = ActiveDocument.Tables(1).Cell(7, 2).Range.Text
'Remove cell marker from string
strName = Left(strName, Len(strName) - 2)

'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
End Sub




"Chr1551" wrote:

Thanks Jean-Guy, I have two separate templates, 1 for quotes and one for
faxes, I opened the one for quotes and opened the VBA editor and clicked
'this document' on the left hand side and pasted your code in there. Is this
correct? I changed the cell reference and then modified the top code as
follows:

strPath = "M:\Quotes\" & strFaxes & Application.PathSeparator

'Get file name from document table _
(First table, third row, second column)
strName = ActiveDocument.Tables(1).Cell(7, 2).Range.Text
'Remove cell marker from string
strName = Left(strName, Len(strName) - 2)

'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

No luck though... it just keeps opening my documents to save as usual and
the document name is still the default!



"Jean-Guy Marcil" wrote:

"Chr1551" wrote:

Thank you both for your help. I'm using Word 2003 and have a table in my
document, I was hoping that I could use one of the cells in the table to name
the file eg. the Quote Reference cell.


Try this variation of my earlier code:


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 table _
(First table, third row, second column)
strName = ActiveDocument.Tables(1).Cell(3, 2).Range.Text
'Remove cell marker from string
strName = Left(strName, Len(strName) - 2)

'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


But, this code will probably have to be modified depending on the exact
content of the target cell...
.



Relevant Pages

  • Re: INSERT INTO statement
    ... Dim StrSQL as String ... Dim strName As String ... O Wilson wrote: ...
    (microsoft.public.access.gettingstarted)
  • Re: Referencing subform during module code
    ... This would work at the form level, but not at the subform. ... Dim strName As String ...
    (comp.databases.ms-access)
  • Re: INSERT INTO statement
    ... get treated as if it were a division problem. ... Dim StrSQL as String ... Dim strName As String ...
    (microsoft.public.access.gettingstarted)
  • Re: concatenate WCHAR*
    ... > LPWSTR SayHello ... > return kTemp; ... > i want to add "Hello " to strName. ... not safe to prepend another string to it. ...
    (microsoft.public.vc.language)
  • Re: How to delete blank line at end of table cell?
    ... the cell marker moves up and the blank line goes away. ... Dim CellText As String ... Jean-Guy Marcil - Word MVP ...
    (microsoft.public.word.vba.general)