Results 1 to 9 of 9
  1. #1
    3 Star Lounger
    Join Date
    Mar 2003
    Location
    Elkins Park, Pennsylvania, USA
    Posts
    325
    Thanks
    0
    Thanked 0 Times in 0 Posts
    OK, I feel like a beginner again.

    I'm simply trying to format a date, but I'm stumped at every turn. Old functions such as Format(Date, "dd-MMM-yyyy") won't run in my new environment.

    Is there a new way to work with dates, or am I missing something? How can I change the date format in my VBA code in Word 2007?

    (BTW, I tried "qualifying" the "format" command--which Word 2007's VB editor did not recognize--by changing it to VBA.Format(Date,"dd-MMM-yyyy" and it worked. Why on earth would I have to specify VBA? Visual Basic for Applications is set as a reference; in fact, I can't DE-select it if I wanted too!)
    <font face="Comic Sans MS">That's what you do in a herd; you look out for each other!</font face=comic> - Mike

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Do you have a module named Format? That would confuse VB.

  3. #3
    3 Star Lounger
    Join Date
    Mar 2003
    Location
    Elkins Park, Pennsylvania, USA
    Posts
    325
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='Mesaka' post='783579' date='08-Jul-2009 13:12']OK, I feel like a beginner again.

    I'm simply trying to format a date, but I'm stumped at every turn. Old functions such as Format(Date, "dd-MMM-yyyy") won't run in my new environment.

    Is there a new way to work with dates, or am I missing something? How can I change the date format in my VBA code in Word 2007?

    (BTW, I tried "qualifying" the "format" command--which Word 2007's VB editor did not recognize--by changing it to VBA.Format(Date,"dd-MMM-yyyy" and it worked. Why on earth would I have to specify VBA? Visual Basic for Applications is set as a reference; in fact, I can't DE-select it if I wanted too!)[/quote]

    THE THOUGHT PLICKENS...
    When I write the same code in a brand new template, it works. The template in which i'm working is one that I'm gradually "converting" to be compatible with Word 2007, and which throws errors when I try to compile it (mostly pertaining to CommandBar objects.) So, I suspect that there was something other than "Date" and "Format" not being part of the new environment! Still, that was one cryptic way of failing!
    <font face="Comic Sans MS">That's what you do in a herd; you look out for each other!</font face=comic> - Mike

  4. #4
    3 Star Lounger
    Join Date
    Mar 2003
    Location
    Elkins Park, Pennsylvania, USA
    Posts
    325
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='HansV' post='783583' date='08-Jul-2009 13:21']Do you have a module named Format? That would confuse VB.[/quote]
    I did, but I since removed it. In fact, once I took out ("commented," actually) the incompatible code so that it would compile, it seems relatively happy. The one weird thing that remains, however, is that "format" will only appear in lower-case now (which was the original case of the "format" module I once had stored in the template.)

    Lower-case function names make me nervous, but maybe someday I'll open up the VB editor and find it back to normal...
    <font face="Comic Sans MS">That's what you do in a herd; you look out for each other!</font face=comic> - Mike

  5. #5
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts
    Your initial symptom (native VBA functions not being recognised) is usually down to a missing reference under Tools-References in the VBEditor.
    Regards,
    Rory

    Microsoft MVP - Excel

  6. #6
    3 Star Lounger
    Join Date
    Mar 2003
    Location
    Elkins Park, Pennsylvania, USA
    Posts
    325
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='rory' post='783928' date='10-Jul-2009 04:03']Your initial symptom (native VBA functions not being recognised) is usually down to a missing reference under Tools-References in the VBEditor.[/quote]
    That's what I figured, too. But it appeared that all necessary references were present and accounted for. In fact, I couldn't de-select the reference to VBA even when i tried. But as I said, once I successfully compiled the code (after having to take out the bogus code leftover from Word 2003 that worked with Command bars and the like), it seemed much happier; at least it compiled and ran.

    However, and quite oddly, the word "format" ALWAYS appears in lower-case anywhere in the project, including in completely non-related routines where it is only being used as an argument for the "Find" method. (I should mention that I have no functions or subs defined as "format", although I once did.) When I use the function in other templates in the same session, however, including in code in NORMAL.dotm, it shows correctly in Init Caps.

    It's a mystery... the code now runs fine, but something is amiss.
    <font face="Comic Sans MS">That's what you do in a herd; you look out for each other!</font face=comic> - Mike

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    VBA internally keeps a list of names that you use/used. If you ever had a user-defined function or procedure named format (with lower case f), that name ended up in the list, and VBA will still use it, even if the function or procedure has long been deleted. It's not something to worry about.

  8. #8
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts
    [quote name='HansV' post='783973' date='10-Jul-2009 14:26']VBA internally keeps a list of names that you use/used. If you ever had a user-defined function or procedure named format (with lower case f), that name ended up in the list, and VBA will still use it, even if the function or procedure has long been deleted. It's not something to worry about.[/quote]
    I wonder if you can fix this by creating a NEW function called Format, and then deleting it.

  9. #9
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    It's worth a try, but in my experience it doesn't work.

Posting Permissions

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