View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
JMay JMay is offline
external usenet poster
 
Posts: 422
Default Create New Folder

Thanks Jim
No, "C:\My Documents\ADSS-01" does not exist.


"Jim Rech" wrote in message
...
At the time the macro breaks does the folder C:\My Documents\ADSS-01"

exist?
It seems to me that a possible flaw is that you're assuming that C:\My
Documents is the active folder when the macro is run.

--
Jim Rech
Excel MVP
"JMay" wrote in message

news:RYBxc.462$tI2.182@fed1read07...
|
| My below code is bombing on the next to last line

"Thisworkbook.SaveAs..."
| Can anyone spot my problem?, please.
| TIA
|
|
| Sub Writingfilenames()
| Dim foldername As String
| Dim Filename As String
| foldername = Sheets("ADSS-01").Name
| If Not FolderExists(foldername) Then MkDir foldername
| Filename = Sheets("ADSS-01").Cells(3, 4)
| ThisWorkbook.SaveAs Filename:="C:\My Documents\" & foldername & "\" &
| Filename & ".xls"
| End Sub
|
| '-----------------------------------------------------------------
| Function FolderExists(Folder) As Boolean
| '-----------------------------------------------------------------
| Dim sFolder As String
| On Error Resume Next
| sFolder = Dir(Folder, vbDirectory)
| If sFolder < "" Then
| If (GetAttr(sFolder) And vbDirectory) = vbDirectory Then
| FolderExists = True
| End If
| End If
| End Function
|
|