私は関連する問題を解決しました。私のワークブックは英国でのみ使用できます。それは様々な場所で集められた現金の詳細を入力するためのシートを持っています。ユーザは、各会場を識別する2つの単一セルフィールドを有する。通常は場所と日付が表示されますが、「日付」フィールドには拡張ロケーション名が含まれることがあります。 日付はdd/mm/yyと入力する必要がありますが、認識可能なものはほとんどとなり、 mm/dd/yyを除きます。 詳細はメモリに保存され、後で印刷用の書式設定されたワークシートにコピーされます。私はメモリ内のストレージを確認しました。しかし、ワークブックが数ヶ月間使用された後、私は、ユーザーがdd/mm/[yy] yy(例えば05/11/17)の形式でセルに有効な日付を入力し、その解釈をmm/dd/[yy] yyも有効な日付を指定すると、日付は11月11日ではなく11月3日として不明瞭に印刷されます。
いくつかのコードスニペット:
'Data structure:
Public Type BkItem 'An item of income, for banking.
ItemName As String 'The first field, just a text name.
ItemDate As Date 'The second field, interpreted as a date.
ItemDateNumber As Long 'The date as internally stored as an integer.
ItemDateString As String 'Re-formatted string, e.g. "05-Nov-17".
' ...
End Type 'BkItem.
'Input validation:
BankData = Range(.Cells(BankFirstRow, BankFirstCol), _
.Cells(BankLastItemLastRow, BankLastCol))
With BankItem(BankTotalItems)
.ItemName = IName
.ItemDateString = BankData(<row>, <col>)
.ItemDateNumber = DateToLong(.ItemDateString)
End With
'Utility routine. "Paper" is a 2-dimensional array of all the data to be printed
'on one or more pages; "Dest" is a global range.:
Sub OutputDataToSheet(ByVal Size As Long, ByRef CurrentSheet As String, _
ByRef Paper() As Variant)
Worksheets(CurrentSheet).Activate
Set Dest = Worksheets(CurrentSheet).Range((Cells(1, 1)), _
(Cells(Size, LastCol)))
Dest.Value = Paper 'Copy data to final sheet for printing.
End Sub 'OutputDataToSheet.
'As we build the array "Paper", it helps to format those cells on the final
'printout worksheet which are going to contain dates.
.Range(Cells(CurRow, L15c01), Cells(CurRow, L15c01)).NumberFormat = "dd-Mmm-yyyy"
'For the item date.
.Range(Cells(CurRow, L15c01), Cells(CurRow, L15c01)).HorizontalAlignment = xlCenter
If IsDate(BankItem(item).ItemDateString) Then
Paper(<row>, <col>) = BankItem(item).ItemDateNumber
'Date as a number, so OutputDataToSheet preserves UK date format.
Else
Paper(<row>, <col>) = BankItem(item).ItemDateString
'Extension of name.
End If 'IsDate(.ItemDateString).
あなたは多くの選択肢がありません。出力を制御したい場合は、より多くのコードが必要です。本当に面倒ではありません! – Rory
[Excel VBA - テキストを日付に変換しますか?](https://stackoverflow.com/questions/20375233/excel-vba-convert-text-to-date) – eirikdaude