Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-21-2020, 02:05 PM
savvy savvy is offline saving with wrong name Windows 10 saving with wrong name Office 2016
Novice
saving with wrong name
 
Join Date: Aug 2020
Location: Toronto
Posts: 17
savvy is on a distinguished road
Default 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
Reply With Quote
  #2  
Old 09-21-2020, 03:36 PM
Guessed's Avatar
Guessed Guessed is offline saving with wrong name Windows 10 saving with wrong name Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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
Reply With Quote
  #3  
Old 09-28-2020, 04:10 AM
savvy savvy is offline saving with wrong name Windows 10 saving with wrong name Office 2016
Novice
saving with wrong name
 
Join Date: Aug 2020
Location: Toronto
Posts: 17
savvy is on a distinguished road
Default

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
Reply With Quote
  #4  
Old 09-28-2020, 04:24 AM
gmayor's Avatar
gmayor gmayor is offline saving with wrong name Windows 10 saving with wrong name Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

As 'final doc' is the folder then you want
Code:
strPath = Environ("USERPROFILE") & "\Documents\final doc\"
strPath = strPath & TextBox2.Text & "." & TextBox1.Text & ".docx"
and that folder must exist. Note the back slash at the end of the first line
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #5  
Old 09-28-2020, 03:38 PM
Guessed's Avatar
Guessed Guessed is offline saving with wrong name Windows 10 saving with wrong name Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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
Reply With Quote
Reply

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
saving with wrong name Word 2010 - Saving Wrong Version WordMaus Word 2 12-24-2013 08:27 AM
saving with wrong name PLEASE HELP-wrong formatting???? bruce Word 10 04-10-2010 03:45 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:43 AM.


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