Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-21-2018, 10:31 PM
Mister-B Mister-B is offline Word Macro driving me crazy Windows 10 Word Macro driving me crazy Office 2016
Novice
Word Macro driving me crazy
 
Join Date: Jun 2018
Posts: 3
Mister-B is on a distinguished road
Unhappy Word Macro driving me crazy

Hi there,

I use mail merge to fill a document with information. All is fine here and all the information is shown correctly in the word document. I filter the mail merge recipients so that only one is shown. I then use VBA Code to save this one page document and send it (with Outlook) as a PDF File. Some of the merge mail fields are used to fill the Body of the mail. One of the fields "MeldeschlussJVA" contains a date which is shown correctly in the document but incorrectly in the Email Body. Here's the field Code that supplies the date:

Format(ActiveDocument.MailMerge.DataSource.DataFie lds"MeldeschlussJVA").Value, "dd.MM.yyyy")



If the date shown in the word file is e.g. 06.07.2018 (July 6), it appears as 07.06.2018 (June 7) in the Mail Body. If the day is past the 13th of the month, the date appears correctly in the mail Body. Can anybody help me understand why this is happening and maybe have a solution to this problem. It's driving me crazy. I send a lot of email using this code and don't want to have to check each one manually to see if the date is correct. Thanks for all help.
Reply With Quote
  #2  
Old 06-21-2018, 11:06 PM
gmayor's Avatar
gmayor gmayor is offline Word Macro driving me crazy Windows 10 Word Macro driving me crazy Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,106
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Unfortunately what you see is what happens with ambiguous dates. The code assumes US format by default. There does not seem to be an easy answer (apart from e.g. using http://www.gmayor.com/ManyToOne.htm to create the PDF and the e-mail).

As the date is correct in the merge document, presumably through the use of a formatting switch on the merge field, have you considered reading the value from the merge document, while it is available, and write it to a string. You can then write the string to your e-mail body (and that will retain the format as it is in the document).
Code:
Dim strDate As String
Dim oFld As Field
    Set oDoc = ActiveDocument
    With oDoc
        .MailMerge.ViewMailMergeFieldCodes = False
        For Each oFld In .Fields
            If InStr(1, oFld.code, "MeldeschlussJVA") > 0 Then
                strDate = oFld.Result
                Exit For
            End If
        Next oFld
    End With
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 06-24-2018, 11:53 PM
Mister-B Mister-B is offline Word Macro driving me crazy Windows 10 Word Macro driving me crazy Office 2016
Novice
Word Macro driving me crazy
 
Join Date: Jun 2018
Posts: 3
Mister-B is on a distinguished road
Default

Thank you very much for you help. The date is now shown correctly in the mail Body.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Numbers are driving me crazy treadhead194 Excel 1 02-01-2016 09:15 AM
Word Macro driving me crazy Word Driving Me Crazy - page numbering mrush Word 4 10-16-2015 10:13 PM
Audio problem thats driving me crazy pcbguy PowerPoint 10 04-26-2012 08:56 AM
A number of issues driving me crazy seanterry125 PowerPoint 0 01-17-2011 04:46 PM
Outlook Journal is Driving me Crazy lujreyes Outlook 0 11-24-2010 05:21 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:02 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft