Results 1 to 6 of 6
  1. #1
    3 Star Lounger
    Join Date
    Feb 2001
    Location
    UK
    Posts
    239
    Thanks
    4
    Thanked 1 Time in 1 Post

    Customised Date Format (VBA - WordXP)

    I have just started to work my way through a book on VBA.

    This shows how to set up a userform that displays the date in the format
    The time and date is 9:00 pm, Saturday, May 10, 2003

    The code is shown in the book as

    Private Sub UserForm_Activate()
    Dim Quote As String
    Quote = "The time and date is "
    lblNow.Caption = Quote & Format(Now, "h:mm am/pm, dddddd")
    End Sub

    Activating the form brings up the message

    Compile Error
    Expected variable or procedure, not module

    I really cannot see what is wrong. The code is exactly as per the book.

    I experimented with FormatDateTime which worked without the customised format but I would like to be able to get the date and time in correct format. Can somebody please explain what I am doing wrong.

    I am using working with Word XP on a Windows XP machine.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Customised Date Format (VBA - WordXP)

    Do you happen to have given one of your modules a name that occurs in the code, such as Quote, or Format? That would lead to a conflict. If you can't find such a conflict, try starting from scratch:

    Quit and restart Word.
    Switch to the Visual Basic Editor.
    Insert a UserForm.
    Place a label on the form and name it lblNow.
    Switch to program code.
    Insert the code as posted.
    Run the form.

  3. #3
    3 Star Lounger
    Join Date
    Feb 2001
    Location
    UK
    Posts
    239
    Thanks
    4
    Thanked 1 Time in 1 Post

    Re: Customised Date Format (VBA - WordXP)

    Hans
    I am a technical author so yes I did have a module called Format with my formatting macros. I have renamed that and the code works without giving an error now. However, the date displays as time and date without showing the day of the week i.e. Saturday. Any ideas what may be causing that.
    Very many thanks for your help.

  4. #4
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Customised Date Format (VBA - WordXP)

    It works properly in Word 2000 on my machine. I don't have Word XP here to try it.
    Charlotte

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Customised Date Format (VBA - WordXP)

    The "dddddd" format shows the date according to your system settings for "Long Date". By default. it shows the day of the week, but if you have changed your system settings, it may be omitted. Try replacing "dddddd" by "dddd d mmmm yyyy" or something like that.

  6. #6
    3 Star Lounger
    Join Date
    Feb 2001
    Location
    UK
    Posts
    239
    Thanks
    4
    Thanked 1 Time in 1 Post

    Re: Customised Date Format (VBA - WordXP)

    After posting I poked around Regional Settings and could see it made a difference. What I didn't know until you posted the information was that dddddd showed the system long date. I had thought that the format shown in the book was intended to show the date in a consistent format, rather than one with links to system date.
    Thanks for your clear help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •