Create Folder and Text File in folder

  • Thread starter Thread starter Todd Huttentsine
  • Start date Start date
T

Todd Huttentsine

Hey guys

On each users Windows 2000 Professional Desktop directory,
I need to create a directory called "RDFMTD". How do I
make sure I get to their desktop as well as how do I
create a Folder called "RDFMTD"? Also how do I create a
file in the RDFMTD directory called RDFMTD.txt?



Thanks
Todd Huttenstine
 
Try this to create a folder "RDFMTD"

Sub test()
Dim wsh As Object
Dim fs As Object
Dim DesktopPath As String
Dim DirString As String

Set wsh = CreateObject("WScript.Shell")
Set fs = CreateObject("Scripting.FileSystemObject")
DesktopPath = wsh.SpecialFolders.Item("Desktop")
DirString = DesktopPath & "\RDFMTD"

If Not fs.FolderExists(DirString) Then
fs.CreateFolder DirString
Else
End If
End Sub

Look forWrite in the VBA help for creating a txt file
 
You can do this also to create a the folder and TXT file

Sub test2()
Dim wsh As Object
Dim fs As Object
Dim DesktopPath As String
Dim DirString As String
Dim fname As String
Dim wb As Workbook

Set wsh = CreateObject("WScript.Shell")
Set fs = CreateObject("Scripting.FileSystemObject")
DesktopPath = wsh.SpecialFolders.Item("Desktop")
DirString = DesktopPath & "\RDFMTD"

If Not fs.FolderExists(DirString) Then
fs.CreateFolder DirString
Else
End If

Application.ScreenUpdating = False
fname = DirString & "\RDFMTD.txt"
Workbooks.Add xlWBATWorksheet
Set wb = ActiveWorkbook
With wb
.SaveAs fname, FileFormat:=xlText
.Close False
End With
Application.ScreenUpdating = True
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Row Delition 1
Finding byte info for files and folders 1
Copy file while in use 3
Installing Files 7
Listbox Selection 1
Listbox 8
Showing Pictures 3
Add Workbook with specified name 2

Back
Top