当前位置: 动力学知识库 > 问答 > 编程问答 >

Excel to Word VBA time incorrect

问题描述:

I have a macro that copies certain values from excel to a word document,

Sub NoFormatTimePaste(timeValue As String)

wdFind.Replacement.Text = ""

wdFind.Forward = True

wdFind.Wrap = wdFindContinue

wdFind.Execute

appWd.Selection.Delete

appWd.Selection.InsertAfter Format(timeValue, "h:mm AM/PM")

End Sub

Dim timeValue As String

timeValue = Cells(Application.ActiveCell.Row, 4).Select

wdFind.Text = "QTIMEQ"

Call NoFormatTimePaste(timeValue)

But its not inserting the time correctly.

In my Excel sheet the times are written in 24 hour format, e.g. 10:30, 12:00, 15:20, 17:45.

Yet every value inserted into the Word document is 12:00 AM regardless of the time written in Excel.

Excel Value Word Value

10:30 12:00 AM

12:00 12:00 AM

15:20 12:00 AM

17:45 12:00 AM

Does anyone know why this might be?

分享给朋友:
您可能感兴趣的文章:
随机阅读: