LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Input box accepting only desired format

Hi,

I want to include a macro in the following code which the InputBox
accepts SourceFolder name in the MMYYYY format only and no other
format else an error message is displayed. Example, if a folder exist
in C:\ drive by the name "$42007" then an error message be displayed
and macro should run only for "042007"

Here is the entire code in which i want my above criteria to be
included.

Any help would be appreciated.


Private Sub CommandButton1_Click()


Dim MMYYYY

Dim BegDate

Dim SourceFolder

Dim FN As String

Dim Dirname As String

Dim fs As Object



Message = "Please enter the Source folder name in the form MMYYYY as
present under path C:\, for Eg. 082006"


Title = "Date"


BegDate = InputBox(Message, Title)


Application.DisplayAlerts = False


If StrPtr(BegDate) = 0 Then


MsgBox "User hit cancel"


Exit Sub


ElseIf Len(BegDate) = 0 Then


MsgBox "User clicked OK with no input"


Exit Sub


End If



EndDate = Mid(BegDate, 1, 2) & "_" & Mid(BegDate, 3)


Application.DisplayAlerts = False


Set fs = CreateObject("Scripting.FileSystemObject")


Dirname = "C:\" & EndDate


SourceName = "C:\" & BegDate



If Not fs.FolderExists(SourceName) Then


MsgBox "Please enter the valid Source Folder Name"


Exit Sub


End If



If Not fs.FolderExists(Dirname) Then


fs.CreateFolder Dirname

Else


MsgBox "The Destination Folder Already Exist"


Exit Sub


End If


Application.ScreenUpdating = False


FileLocation = "c:\" & BegDate & "\" & "*.xls"




FN = Dir(FileLocation)


If FN = "" Then


MsgBox "No files Found in the Source Folder"


Exit Sub


End If


Do Until FN = ""


If Mid(FN, 4, 1) = "_" And Mid(FN, 5, 2) = Mid(BegDate, 1, 2)
Then


oldname = "C:\" & BegDate & "\" & FN


newname = "C:\" & EndDate & "\" & Mid(FN, 1, 3) & "_" &
Mid(BegDate, 1, 2) & "_" & Mid(BegDate, 3) & ".xls"



FileCopy oldname, newname


Else: MsgBox "Some or All files in the Source folder doesn't
have not a valid monthname. Only the files with valid monthname have
been transferred to destination folder"


Exit Sub


End If

FN = Dir


Loop


Application.ScreenUpdating = True


End Sub



Any help would be appreciated.

Thanks,
Amit

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to change date accepting format to day-month-year masc Excel Discussion (Misc queries) 2 May 18th 10 04:59 PM
format to a desired style and order Khiller Excel Worksheet Functions 0 July 10th 06 09:00 PM
Reads entire *.txt file into string opposed to a desired line by line input. ej_user Excel Programming 3 October 11th 04 07:15 PM
First textbox in form not accepting input properly Jack Excel Programming 4 October 7th 04 09:37 PM
How to get desired format in textbox linked to a cell [email protected] Excel Programming 3 January 14th 04 02:05 PM


All times are GMT +1. The time now is 11:15 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"