2016-10-06 1 views
0

달러 통화 형식을 사용했습니다. 그것은 잘 작동합니다. 유로, 파운드와 같은 다른 통화에 대해 수행하려는 동일한 통화 서식. 다음은 내가 시도한 코드입니다. Pls 도움.통화 VBA를 사용하여 유로화로 된 단어 서식

코드 :

Sub CurrencyFormat_UK() 
' 
' Currency 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 IsNumeric(oRng) Then 
     .Text = FormatCurrency(Expression:=.Text, NumDigitsAfterDecimal:=2, _ 
       IncludeLeadingDigit:=vbTrue, UseParensForNegativeNumbers:=vbTrue) 
     End If 
     If oRng.Characters.count = 1 Then GoTo Skip 
     On Error GoTo Skip 
     'Catch errors here 
     If InStr(oRng.Text, "€") = False Then 
     oRng.Font.Color = wdColorRed 
     oRng.Select 
     MsgBox "Cell content is not numerical.", , "Error" 
     Selection.Collapse wdCollapseEnd 
     End If 
Skip: 
    End With 
    Next oCl 
lbl_Exit: 
Exit Sub 
End Sub 
+0

어떤 오류가 있습니까? 우리는 어떻게하면 작동하지 않는지 말하지 않으면 어떻게 도울 수 있습니까? – CyberClaw

+0

사실 "FormatCurrency"함수는 달러의 코드 형식에서 자동으로 사용됩니다. 다른 통화로도 형식을 지정할 수있는 다른 방법이 있습니까? –

+0

누군가가 당신을 위해 일하기를 원하면 프로그래머에게 돈을 지불해야합니다. 이 웹 사이트는 "의심의 여지가 있거나 실수를 저질렀을 때 도움을 요청하는 프로그래머를위한 것입니다."제발 나를 위해 모든 일을 해주십시오, ktkxbai! " – CyberClaw

답변

0

그냥하는 NumberFormat를 대신 사용합니다.

SheetCur 시트에서 B 열 전체를 GBP (£)로 포맷하려고한다고 가정 해 봅시다. 코드는 다음과 같습니다 :

Worksheets("SheetCur").Columns("A").NumberFormat = "£#,##0.00_)" 

이렇게하면 £ 555,00처럼 보일 것입니다. 당신이 통화 및 숫자 사이에 공간을 남겨 둡니다 단지뿐만 아니라 문자열에 공간을 남겨 :

.NumberFormat = "£ #,##0.00_)" 

당신이 수 후 통화를 원하는 마찬가지로, 당신은 사용할 수 있습니다

.NumberFormat = "#,##0.00 £_)"