• Format Date in Word 2007

    Author
    Topic
    #461059

    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!)

    Viewing 2 reply threads
    Author
    Replies
    • #1168111

      Do you have a module named Format? That would confuse VB.

      • #1168121

        Do you have a module named Format? That would confuse VB.

        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…

    • #1168115

      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!)

      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!

    • #1168488

      Your initial symptom (native VBA functions not being recognised) is usually down to a missing reference under Tools-References in the VBEditor.

      • #1168558

        Your initial symptom (native VBA functions not being recognised) is usually down to a missing reference under Tools-References in the VBEditor.

        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.

        • #1168560

          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.

          • #1168592

            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.

            I wonder if you can fix this by creating a NEW function called Format, and then deleting it.

            • #1168596

              It’s worth a try, but in my experience it doesn’t work.

    Viewing 2 reply threads
    Reply To: Format Date in Word 2007

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: