View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Per Jessen Per Jessen is offline
external usenet poster
 
Posts: 1,533
Default subfolder and file creation

Hi

Thanks for your reply.

You can do it like this:

If wbB Is Nothing Then
Set wbB = Workbooks.Open("C:\Temp\Template.xls")
wbB.SaveAs "C:\Temp\" & Mnth & "\" & fName
End If

Regards,
Per

"Robert Crandal" skrev i meddelelsen
...
Thank you very much. That code worked very nicely for me.

I have another question now. If the file doesnt exist. I plan to create
the file by copying a file and renaming it to the target filename. So,
what is the proper way to copy a file to another filename (and
possibly rename the file at the same time).

thank you!


"Per Jessen" wrote in message
...
Hi

Look at this :

Sub test()
Dim wbA As Workbook
Dim wbB As Workbook

Set wbA = ThisWorkbook
Mnth = Format(Date, "MMMm")
fName = "FileToOpen.xls"
Set fs = CreateObject("Scripting.FileSystemObject")
If fs.FolderExists("C:\Temp\" & Mnth) Then
If fs.FileExists("C:\Temp\" & Mnth & "\" & fName) Then
Set wbB = Workbooks.Open("C:\Temp\" & Mnth & "\" & fName)
Else
'File does not exists
End If
Else
fs.createfolder ("C:\Temp\" & Mnth)
End If
If wbB Is Nothing Then
msg = MsgBox("File does not exists", vbExclamation + vbOKOnly, "Merry
Christmas")
End If
End Sub

Hopes this helps.
...
Per