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!
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!