#1
|
|||
|
|||
saving with wrong name
I want to save file as:
firstname.lastname.docx in folder c:\users\savvy\documents\final doc\ firstname and lastname are bookmarks from userform but am getting runtime error 5152 this is not a valid filename code: strPath = Environ("USERPROFILE") & "\Documents\final doc" ActiveDocument.SaveAs strPath & TextBox2.Text & "." & TextBox1.Text & ".docx" any advice appreciated |
#2
|
||||
|
||||
I think you missed a backslash. Add another couple of lines to see what the full path is
strPath = Environ("USERPROFILE") & "\Documents\final doc" strPath = strPath & TextBox2.Text & "." & TextBox1.Text & ".docx" Debug.Print strPath ActiveDocument.SaveAs strPath
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#3
|
|||
|
|||
Thanks. I tried everything but ended up with saved file with wrong name
final doctextbox2.textbox1.docx So I changed strPath = Environ("USERPROFILE") & "\Documents\final doc" to strPath = "C:\Users\user\Documents\final doc" and that works |
#4
|
||||
|
||||
As 'final doc' is the folder then you want
Code:
strPath = Environ("USERPROFILE") & "\Documents\final doc\" strPath = strPath & TextBox2.Text & "." & TextBox1.Text & ".docx"
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#5
|
||||
|
||||
It is also possible that the text in TextBox2 and TextBox1 contains an invalid character which could cause an error. For instance, you wouldn't be allowed to save a filename containing any of these characters:
<>"|?*
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Email macro saving the wrong document | andywal6 | Mail Merge | 1 | 08-13-2019 09:00 PM |
Am I using the wrong formula? | Father | Excel | 2 | 05-24-2017 12:27 PM |
Outlook 2010: Saving attachments opens up wrong windows folder to save in | jeroen | Outlook | 0 | 09-29-2015 01:51 AM |
Word 2010 - Saving Wrong Version | WordMaus | Word | 2 | 12-24-2013 08:27 AM |
PLEASE HELP-wrong formatting???? | bruce | Word | 10 | 04-10-2010 03:45 PM |