How do I specify a temporary file path

selkov

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

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
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
 
Upvote 0
That script shows me what path is current.
I wish to Specify a location to save a file to.
 
Upvote 0
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
 
Upvote 0
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
 
Upvote 0
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
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,214,431
Messages
6,119,458
Members
448,899
Latest member
maplemeadows

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
Back
Top