Search code examples
vbamacospdfms-wordmacos-sierra

Saving MS word (docx) as pdf on Mac OS X with one click using macros


I have a question on how to edit the following macros to save MS word (.docx) file as PDF on macOS Sierra without .docx in the file name. That is, the macros works perfectly BUT it always saves files as, for example, letter.docx.pdf. It is a very easy option to save in pdf with one click only.

And I would appreciate if someone could help to me amend the macros below so that there is no .docx in the file name. I have tried to hide extensions in Finder, but that does not seem to help:


Sub SaveActiveDocAsPDF()

On Error Resume Next

ActiveDocument.SaveAs _
fileName:=ActiveDocument.FullName & ".pdf", _
FileFormat:=wdFormatPDF
End Sub

Thank you very much in advance.


Solution

  • You need to remove the existing file extension before adding the new one. Like this:

    Sub SaveActiveDocAsPDF()
    
    On Error Resume Next
    
    Dim saveName As String
    saveName = ActiveDocument.FullName
    saveName = Left(saveName, Len(saveName) - 5) & ".pdf"
    
    ActiveDocument.SaveAs fileName:=saveName, _
    FileFormat:=wdFormatPDF
    End Sub