![]() |
#1
|
|||
|
|||
![]()
Hello all,
I am having trouble getting my macro to save my document into the desired location. The program I use attempts to save documents to a default temporary folder, and even after recording the process it still won't save my document to my desired location. Am I doing something wrong? How can I get my macro to override the default location for documents? Code:
Sub Savetolocation ' ' ChangeFileOpenDirectory "C:\Users\dwirony\My Documents\Overflow Folder\" ActiveDocument.SaveAs2 FileName:=ActiveDocument.Fullname, FileFormat:= _ wdFormatXMLDocument, LockComments:=False, Password:="", AddToRecentFiles _ :=True, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts _ :=False, SaveNativePictureFormat:=False, SaveFormsData:=False, _ SaveAsAOCELetter:=False, CompatibilityMode:=14 End Sub |
#2
|
||||
|
||||
![]()
ActiveDocument.FullName includes the entire path so you are simply saving the file over itself. Try
Code:
Sub Savetolocation() Dim sLocation As String sLocation = "C:\Users\dwirony\My Documents\Overflow Folder\" & ActiveDocument.Name ActiveDocument.SaveAs2 FileName:=sLocation, FileFormat:=wdFormatXMLDocument, CompatibilityMode:=14 End Sub
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#3
|
|||
|
|||
![]() Quote:
Thank you for your assistance! |
#4
|
||||
|
||||
![]()
That requires a bit more effort. This takes the current filename before the first period (assuming the first period is at the file extension), and appends the new file extension
Sub Savetolocation() Dim sLocation As String, sFile as String sFile = Split(ActiveDocument.Name,".")(0) & ".docx" sLocation = "C:\Users\dwirony\My Documents\Overflow Folder\" & sFile ActiveDocument.SaveAs2 FileName:=sLocation, FileFormat:=wdFormatXMLDocument, CompatibilityMode:=14 End Sub
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#5
|
||||
|
||||
![]()
Whoops, I tried to edit and lost the message.
Try this Code:
Sub Savetolocation() Dim sLocation As String, sFilename as String sFilename = Split(ActiveDocument.Name,".")(0) & ".docx" sLocation = "C:\Users\dwirony\My Documents\Overflow Folder\" ActiveDocument.SaveAs2 FileName:=sLocation & sFilename, FileFormat:=wdFormatXMLDocument, CompatibilityMode:=14 End Sub
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#6
|
|||
|
|||
![]() Quote:
|
#7
|
||||
|
||||
![]()
If there are more than one period characters, using split creates a few more problems. It would be better to use
Code:
sFile = ActiveDocument.Name sFile = Left(sFile, InStrRev(sFile, Chr(46))) & "docx" 'or, if you want to add some text to the end of the filename 'sFile = Left(sFile, InStrRev(sFile, Chr(46)) - 1) & "-sometext.docx"
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
staicumihai | Word VBA | 2 | 10-28-2016 03:01 AM |
![]() |
klpw | Excel Programming | 2 | 12-24-2015 12:31 AM |
![]() |
bigbird69 | Word VBA | 13 | 11-18-2012 10:06 PM |
outlook 2003 always not remove temp copy of opened attachments in temporary folder | c.itech | Outlook | 0 | 06-20-2011 10:34 PM |
Error 451 - Couldīt Open Temp file | greenberet | Outlook | 1 | 09-06-2010 05:35 AM |