How do I specify a temporary file path

selkov

Well-known Member
Joined
Jan 26, 2004
Messages
781
How do I specify a temporary file path where I can save files to?
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college

dk

MrExcel MVP
Joined
Feb 15, 2002
Messages
2,942
Try this. It will return the path of the temporary folder on the machine:-

Code:
Sub TempFolder()
    Dim oFSObj As Object
    Dim strTempFolder As String

    Set oFSObj = CreateObject("Scripting.FileSystemObject")

    strTempFolder = oFSObj.GetSpecialFolder(2).Path

    MsgBox strTempFolder

End Sub
 

selkov

Well-known Member
Joined
Jan 26, 2004
Messages
781
That script shows me what path is current.
I wish to Specify a location to save a file to.
 

Alan Nicoll

Board Regular
Joined
Feb 3, 2004
Messages
71
My usual practice is to save the current directory, change to the one I want, then change back, e.g.:
Code:
ThisDirectory = CurDir
ChDir NewDirectory
[do stuff here]
ChDir ThisDirectory

HTH
 

selkov

Well-known Member
Joined
Jan 26, 2004
Messages
781

ADVERTISEMENT

I am getting a sytanx error & my help file does not work. Can you correct this?

ThisDirectory = CurDir
ChDir c:\zzzz\2004 ' error here!!

[do stuff here]
ChDir ThisDirectory


Thanks
 

TryingToLearn

Well-known Member
Joined
Sep 10, 2003
Messages
723
Does this do what you want?

Code:
Sub saveto()
    Dim fullname, pth, rsp

    pth = InputBox("Enter the Folder to save file in" & Application.Rept(vbLf, 1) _
                 & "i.e. C:\mydocuments" & Application.Rept(vbLf, 1) _
                 & "or   D:", "FOLDER NAME")
    If pth = vbNullString Then
        rsp = MsgBox("File will be saved to " & Application.DefaultFilePath, vbYesNo)
        If rsp <> vbYes Then
            Exit Sub
        End If
    End If
    fullname = pth & "\" & Thisworkbook.Name
    ThisWorkbook.SaveAs fullname, , , , , , , , True    ' adds to MRU list
    MsgBox "File saved as:" & Chr(10) & Chr(10) & fullname, vbExclamation, "STATUS"
End Sub
 

Alan Nicoll

Board Regular
Joined
Feb 3, 2004
Messages
71
selkov said:
I am getting a sytanx error & my help file does not work. Can you correct this?

ThisDirectory = CurDir
ChDir c:\zzzz\2004 ' error here!!

[do stuff here]
ChDir ThisDirectory


Thanks

You need quotes around the path:
Code:
ChDir "c:\zzzz\2004"

HTH
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,152,163
Messages
5,768,555
Members
425,481
Latest member
ihumanl

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top