PDA

View Full Version : [SOLVED:] save as



Kilroy
10-25-2016, 09:37 AM
OK I've done a lot of research and can't piece together what I need. There numerous posts asking for this so hopefully someone can help me tweek this a bit. This code opens a small window asking what you want to name your new document only if it's new which suits me fine but I can't figure out how to get it ask for a location. It just picks an open folder or defaults to the "documents" folder. Is there a way to tell it where to store the file? like a save as window?


Sub SaveAsDocFile()
Dim strDocName As String
Dim intPos As Integer

strDocName = ActiveDocument.Name
intPos = InStrRev(strDocName, ".")

If intPos = 0 Then

strDocName = InputBox("Please enter the name " & _
"of your document.")
Else

strDocName = Left(strDocName, intPos - 1)
strDocName = strDocName & ".docx"
End If

ActiveDocument.SaveAs FileName:=strDocName, _
FileFormat:=wdFormatDocument
End Sub

mikewi
10-25-2016, 11:59 AM
I'm looking forward to seeing the answer to this as well.

Paul_Hossler
10-25-2016, 12:00 PM
Try something like this

Be advised that if you try to save a document with this macro in the document you'll get error 6294, Incompatible Filetype and Extension




Option Explicit
Sub SaveAsDocFile()
Dim strDocName As String
Dim intPos As Long

strDocName = ActiveDocument.Name
intPos = InStrRev(strDocName, ".")

If intPos = 0 Then

'-2 The Close button.
'-1 The OK button.
'0 (zero) The Cancel button.
'> 0 (zero) A command button: 1 is the first button, 2 is the second button, and so on.

With Application.Dialogs(wdDialogFileSaveAs)
If .Display = -1 Then strDocName = .Name
End With

Else
strDocName = Left(strDocName, intPos - 1)
strDocName = strDocName & ".docx"
End If

ActiveDocument.SaveAs FileName:=strDocName, FileFormat:=wdFormatDocument
End Sub

Kilroy
10-25-2016, 12:27 PM
I had to drop ", FileFormat:=wdFormatDocument" from the last line to get it to work. but works good now. Thanks Paul

Paul_Hossler
10-25-2016, 12:36 PM
If your macro was in an AddIn, then I think you'd have been OK to save ActiveDocument that way