Hello,
So I have a word document that when the user closes it out, I would like the document to save itself in its current folder as well as save as a PDF (which is already existing and should be overwritten) in a different folder. In order to reference the correct PDF when saving, I am using the text (just an 9-digit number) from a table cell in the word document and using that text as part of the folder path to the PDF file.
The problem is that when I am storing the 9-digit number as a string variable ("QN" below in the code), the variable that I am using for the file path (RefDocPath) to the PDF file will not store any text after the "QN" variable. I inserted a msgbox to see what was being stored and it shows a dot in the string after the "QN" variable. (See attached photo). I've never seen this before and I do not know what to do.
Code:
Private Sub Document_Close()
Dim RefDocPath As String
Dim QN As String
Dim Doc As Document
Application.DisplayAlerts = False
QN = ThisDocument.Tables(1).Cell(2, 2).Range.Text
RefDocPath = "G:\Shared\Ref_Docs\Quality Alerts\X_X_" & QN & "_X_X_QualityAlerts.pdf"
MsgBox RefDocPath
ThisDocument.Save
ThisDocument.SaveAs2 FileName:=(RefDocPath), AddtoRecentFiles:=False, FileFormat:=wdFormatPDF
Application.DisplayAlerts = True
End Sub