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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 48

Expert Comment

ID: 12343935
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

719 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