Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA Beginner Here - Help needed to change path.

Status
Not open for further replies.

ReportSmithing

Programmer
Apr 15, 2005
41
US
Currently, I have a VB App that calls a Word document using the shell command, once the Word doc is opened, I poke data into bookmarks on that Word doc and then I use a DDE Execute command from VB to run the "SaveMeToTemp" macro located in my Word doc.

I'm not very experienced at Word, so today by mistake I accidently erased my macro! And of course I can't find the same macro on the internet where I found it in the first place!

My goal here is to have the Word doc macro run and the Word document save automatically to C:\TEMP - I want to totally change the path name from it's original location. The below code (my feeble attempt) doesn't work very well - it will save the document to the desired location, but the active document still resides in the original location from where I opened it. Could someone help me to have the active path name change to C:\TEMP also?


Sub SaveMeToTemp()
Dim strFileA, strFileB, strFileC
ActiveDocument.Save
strFileA = ActiveDocument.Name
strFileB = "C:\TEMP\" & Format(Date, "yyyy-mm-dd") & "_" & Format(Time, "hh-mm-ss") & "_" & strFileA
strFileC = ActiveDocument.FullName
ActiveDocument.SaveAs FileName:=strFileB
ActiveDocument.SaveAs FileName:=strFileC
End Sub

Thanks for you help.
 
RS,

Try something like
Code:
ChDir "C:\TEMP"

I suggest using error trapping unless you always know the particular path exists. Also, you may want to save the existing default path then restore it later. You can use
Code:
 sSavePath = CurDir


HTH
Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top