0
我的要求是我要更改Word文档中表格中选定单元格的日期格式。我尝试了下面的代码。如果我选择一个日期,我可以更改日期格式。但是,我无法更改所选号码的日期格式。表格中的单元格。 ....请帮助通过选择一个编号在字中进行日期格式设置。表格中的单元格
代码:
Sub ConvertDateFormat()
'
' Date formating
'
Dim oCl As Word.Cell
Dim oRng As Range
'
' Condition to check the selected data
'
If Selection.Type = wdSelectionIP Or _
Not Selection.Information(wdWithInTable) Then
MsgBox "Select a cell or range of cells before running" _
& " this macro.", , "Nothing Selected"
Exit Sub
End If
For Each oCl In Selection.Cells
Set oRng = oCl.Range
'
'Drop of the end of cell mark
'
oRng.End = oRng.End - 1
With oRng
If IsDate(oRng) Then
Selection.Text = Format(Selection.Text, "yyyy-MM-dd")
Selection.Collapse wdCollapseEnd
Else ' not a date - end loop
MsgBox ("Invalid Date Format")
End If
End With
Next oCl
lbl_Exit:
Exit Sub
End Sub
非常感谢。有用 –