Excel VBAinputdate,然后以英国格式输出date

我已经做了一个简单的macros来将数据从一个标签移动到另一个标签,并添加一个date来简化我们构build日志的过程。

但是,当我要求input一个date时 – VBA是否会把你的date变成美国的date。 我需要的是用户input一个英国date和输出是相同的英国date – 但是,如果我input一个英国date它作为一个美国date出来。

我能想到的唯一方法就是以美国格式inputdate,并使用Format(str, "dd/mm/yyyy")以英国格式输出date,但这并不理想。

一个简单的方法将是一个很大的帮助,因为macros是为了团队而不是我自己。

 Dim wb As Workbook, wk1 As Worksheet, wk2 As Worksheet, rng As Range, str As String Sub Journal() Set wb = ThisWorkbook Set wk1 = ActiveSheet Set wk2 = wb.Sheets("CBCS Journal") str = InputBox(Prompt:="What date would you like to post this journal for?", _ Title:="Enter the posting date", Default:=Format(Now, "dd/mm/yyyy")) For i = 1 To wk1.Range("A" & Rows.Count).End(xlUp).Row - 9 wk2.Range("B" & i + 1).Value = str End Sub 

这适用于我:

 Dim str As String Dim splitStr() As String Dim strFormat As String Dim d As Date 'Your preferred date format strFormat = "dd/mm/yyyy" 'Get string representing date str = InputBox(Prompt:="What date would you like to post this journal for?", _ Title:="Enter the posting date", Default:=Format(Now, strFormat)) 'Parse the date string splitStr = Split(str, "/") d = DateSerial(CInt(splitStr(2)), CInt(splitStr(1)), CInt(splitStr(0))) 'Display it in the proper format With Range("A1") .Value = d .NumberFormat = strFormat End With