timedate format in excel vba

Posted on 2004-10-18
Last Modified: 2008-02-01
Hi all,

I need to format a string in a vba userform.

what i have is:

    TextBox1.Value = DateTime.Now - 2
    TextBox2.Value = DateTime.Now - 1

this gives me the dates in the forrmat  mm/dd/yyyy hh:mm:ss AM/PM
I need the format dd/mm/yyyy only. can someone tell me how to reformat this.

I tried doing

dim date1 =
dim day1 =
dim month1 = date1.month
dim year1 = date1.year
dim d1 = day1 & "/" & month1 & "/" & year1

as well as trying date1.toString("dd/mm/yyyy")

can someone tell me where I'm going wrong???
Question by:cedop
  • 5
LVL 48

Expert Comment

ID: 12343781

Author Comment

ID: 12343923
that didn't work, got the error message

Compile Error:
Cant find project or library

with the word 'Format' highlighted
LVL 48

Expert Comment

ID: 12343934
try vba.format
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

LVL 48

Expert Comment

ID: 12343935
LVL 48

Expert Comment

ID: 12343956
LVL 48

Accepted Solution

Mikal613 earned 125 total points
ID: 12343975

go into the VB editor

then select Tools/References

have a look for any that are missing (its says MISSING)

then make a note of these, then uncheck, click ok to get out of references, then go back in again and find those references (might be on list or you need to browse thru it)
If it is a third party you may need to get hold of that file again (and reference it in here)

also - do a debug/compile in the code


Featured Post

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article ( for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question