PDA

View Full Version : Saving to a folder and prompting user to enter file name



Ray.Mason
08-23-2012, 02:39 AM
Hi Guys!

I have the following code that should save to my preferred location but is failing and am sure there should be a problem which I am failing to identify.

Also is it possible to prompt the user to enter a name for the generated file before saving it?

Dim SaveFolder As String
Dim wdDoc As Word.Document

SaveFolder = "C:\Users\RM\Desktop\Projects\"
Set wdApp = New Word.Application

On Error Resume Next
Set wdApp = GetObject(, "Word.Application")
If Err.Number <> 0 Then 'Word isn't already running
Set wdApp = CreateObject("Word.Application")
End If
On Error GoTo 0

Set wdDoc = wdApp.Documents.Add(Template:="C:\Users\RM\Desktop\ReportTemplateSample1.dotx")

wdApp.Visible = True

'Doing my stuff here

Savename = SaveFolder + "Monthly Report.docx"
wdDoc.SaveAs (Savename)
wdDoc.Close

Many thanks!

GTO
08-23-2012, 03:10 AM
Not tested at all, but first, get rid of the plus sign and use the ampersand, which indicates more clearly to vbide, concatenation, versus addition.

Savename = SaveFolder + "Monthly Report.docx"

Bob Phillips
08-23-2012, 03:22 AM
Look at GetSaveAsFilename in VBA help for getting the user to specify the file name.

GTO
08-23-2012, 03:51 AM
Oopsie... I sorta missed that part:oops:

Ray.Mason
08-23-2012, 03:55 AM
Got it! Thanks guys.