![]() |
#1
|
|||
|
|||
![]()
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 |
#2
|
|||
|
|||
![]()
Did you try a message box to test for the string value of QN as well? Is it possible that it's capturing that extra dot at the end there?
|
#3
|
|||
|
|||
![]()
Thanks dwirony, I don't know why I didn't think of that. I tried it and yes, that dot is appearing in the msgbox with the QN string variable. Why is that doing that and how do I get rid of it?
|
#4
|
|||
|
|||
![]()
Apparently the dot at the end of the text is the character for table end, which is showing up when i call the cell text. There is another character at the end too which I'm guessing marks the end of the cell. To workaround this I used the Left() function to eliminate the last 2 characters of the string:
Code:
QN = Left(ThisDocument.Tables(1).Cell(2, 2).Range.Text, Len(ThisDocument.Tables(1).Cell(2, 2).Range.Text) - 2) |
#5
|
|||
|
|||
![]()
Ahh there ya go. I wasn't sure if it was the table end marker or just what was populating in your table - I was going to provide a solution to eliminate that symbol all together but your solution is much more efficient!
|
#6
|
||||
|
||||
![]()
Even more efficient:
QN = Split(ThisDocument.Tables(1).Cell(2, 2).Range.Text, vbCr)(0)
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
![]() |
Tags |
concatenate, saveas, word to pdf |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
How to find all string within string. | PRA007 | Word VBA | 18 | 02-12-2016 08:11 PM |
![]() |
Jim_H | Word | 5 | 04-13-2015 04:41 PM |
![]() |
omahadivision | Excel Programming | 12 | 11-23-2013 12:10 PM |
![]() |
empressive | Word | 10 | 01-17-2012 09:17 PM |
![]() |
LabanM | Outlook | 1 | 09-28-2010 02:27 PM |