2016-10-19 54 views
0

我正在使用下面的代碼來更改日期格式。將此宏用作使用XML的功能區中的下拉選項。但它給「參數不可選」錯誤。編譯錯誤:參數不可選

請幫我在哪裏做錯了。

Public Sub ConvertDateFormat1(control As IRibbonControl) 
' 
' date formating (MM/DD/YYYY) 
' 

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 
     oRng.Text = Format(oRng.Text, "MM/DD/YYYY") 

    Else ' not a date - end loop 
     MsgBox ("Invalid Date Format") 
    End If 
    End With 
    Next oCl 
lbl_Exit: 
Exit Sub 
End Sub 

回答

0

按照其簽名你的子會期望一個control參數類型的IRibbonControl

,但因爲它實際上並不使用它,你可能想將其刪除:

Public Sub ConvertDateFormat1() 
    ' rest of your sub code as it is 
+0

@PankajKumar,你通過了嗎? – user3598756