Language version: Microsoft Word/Excel version 16.41
Operating system: Mac OS Mojave 10.14.6
I am trying to use Excel VBA to save a Word document on my desktop.
Result:
Run time error 5152. This is not a valid file name. Try one or more of the following:
-Check the path to make sure it was typed correctly
-Select a file from the list of files and folders
I am using Microsoft Excel version 2008 and Microsoft Word version 2008. I am using early binding and I have selected Microsoft Excel, Office, and Word 16.0 Object Library. (Does the 16.0 object library seem odd for version 2008?) (Windows 10 Pro version 2004. Microsoft Office 365 Subscription)
I am trying to follow this tutorial.
Line with error:
.ActiveDocument.SaveAs2 Environ("UserProfile") & "\Desktop\MovieReport.docx"
My code :
Option Explicit
Sub CreateBasicWordReportEarlyBinding()
Dim wdApp As Word.Application
Set wdApp = New Word.Application
With wdApp
.Visible = True
.Activate
.Documents.Add
With .Selection
.ParagraphFormat.Alignment = wdAlignParagraphCenter
.BoldRun
.Font.Size = 18
.TypeText "Best Movies Ever"
.BoldRun
.Font.Size = 12
.TypeText vbNewLine
.ParagraphFormat.Alignment = wdAlignParagraphLeft
.TypeParagraph
End With
Range("A2", Range("A2").End(xlDown).End(xlToRight)).Copy
.Selection.Paste
.ActiveDocument.SaveAs2 Environ("UserProfile") & "\Desktop\MovieReport.docx"
.ActiveDocument.Close
.Quit
End With
'Set wdApp = Nothing
End Sub
C:\MovieReport.docx
– xwhitelight"C:\Users\" & Environ("UserProfile") & "\Desktop\MovieReport.docx"
? – dwirony.ActiveDocument.SaveAs Filename:="C:\Users\" & Environ("UserProfile") & "\Desktop\MovieReport.docx"
? – dwirony