Create Folder and Text File in folder

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
 
R

Ron de Bruin

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
 
R

Ron de Bruin

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
 
Top