VBA Equivalent for Excel Function

  • Thread starter Thread starter Bob Zimski
  • Start date Start date
B

Bob Zimski

I am looking for the VBA equivalent for the following function:

=isnumber(value(mid("Export20090224.xls",7,8)))

What I am trying to do is make sure that when the user saved the filename
that they entered the date properly as in 20090224 rather than 2009224. Maybe
this is a weak approach as I am just testing for the length more than
enything else. Can I get the date from the 'saved date' stamp pehaps?

If there is an even better way of doing this, then that would be great.

Thanks
 
Public Function GetDateName(dte As Date) As String
GetDateName = Format(dte, "YYYYMMDD")
End Function
 
Hi Bob,

Dim strFileName As String

strFileName = "Export" & Format(Date, "yyyymmdd") & ".xls"

MsgBox strFileName 'For testing only
 
You can test this way (where the variable FileName is assumed to hold the
filename entered by the user)...

If FileName Like "*########.xls" Then
MsgBox "The shape of the filename appears to be correct"
Else
MsgBox "Something appears to be wrong with the filename"
End If

If the
 
Hi again Bob,

Not sure if that code needed any more explanation but to save you time just
in case.

Date in VBA is today's date.

You can use a date variable in place of Date. The following code assigns
today's date to a date variable and uses the date variable. You could assign
any valid date to a date variable to use for the file name.


Dim dateToDay As Date
Dim strFileName As String

dateToDay = Date 'Today's date

strFileName = "Export" & Format(dateToDay, "yyyymmdd") & ".xls"

MsgBox strFileName 'For testing only
 

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

Back
Top