Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-30-2017, 09:54 AM
aramaglia aramaglia is offline String will not fully concatenate Windows 7 64bit String will not fully concatenate Office 2016
Novice
String will not fully concatenate
 
Join Date: Jan 2017
Posts: 8
aramaglia is on a distinguished road
Question String will not fully concatenate

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

Attached Images
File Type: png Capture.PNG (21.2 KB, 17 views)
Reply With Quote
  #2  
Old 01-30-2017, 10:53 AM
dwirony dwirony is offline String will not fully concatenate Windows 7 64bit String will not fully concatenate Office 2003
Advanced Beginner
 
Join Date: Oct 2016
Posts: 49
dwirony will become famous soon enough
Default

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?
Reply With Quote
  #3  
Old 01-30-2017, 11:02 AM
aramaglia aramaglia is offline String will not fully concatenate Windows 7 64bit String will not fully concatenate Office 2016
Novice
String will not fully concatenate
 
Join Date: Jan 2017
Posts: 8
aramaglia is on a distinguished road
Default

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?
Reply With Quote
  #4  
Old 01-30-2017, 11:05 AM
aramaglia aramaglia is offline String will not fully concatenate Windows 7 64bit String will not fully concatenate Office 2016
Novice
String will not fully concatenate
 
Join Date: Jan 2017
Posts: 8
aramaglia is on a distinguished road
Default

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)
Reply With Quote
  #5  
Old 01-30-2017, 12:43 PM
dwirony dwirony is offline String will not fully concatenate Windows 7 64bit String will not fully concatenate Office 2003
Advanced Beginner
 
Join Date: Oct 2016
Posts: 49
dwirony will become famous soon enough
Default

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!
Reply With Quote
  #6  
Old 01-30-2017, 04:37 PM
macropod's Avatar
macropod macropod is offline String will not fully concatenate Windows 7 64bit String will not fully concatenate Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Even more efficient:
QN = Split(ThisDocument.Tables(1).Cell(2, 2).Range.Text, vbCr)(0)
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Tags
concatenate, saveas, word to pdf



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to find all string within string. PRA007 Word VBA 18 02-12-2016 08:11 PM
String will not fully concatenate Format Painter must be used twice to work fully Jim_H Word 5 04-13-2015 04:41 PM
String will not fully concatenate Way to search for a string in text file, pull out everything until another string? omahadivision Excel Programming 12 11-23-2013 12:10 PM
String will not fully concatenate How to fully justify columns empressive Word 10 01-17-2012 09:17 PM
String will not fully concatenate Outlook 2007 Not Fully Closing LabanM Outlook 1 09-28-2010 02:27 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:36 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft