2016-10-06 12 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(£)にフォーマットしたいとしましょう。コードは次のようになります:

これは£555,00のようなものを作成します。あなたが通貨と番号の間にスペースを残しておきたい場合は、単にだけでなく、文字列内のスペースを残す:

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

同様にあなたは番号の後に通貨をしたい場合は、あなたが使用できます。

.NumberFormat = "#,##0.00 £_)" 
関連する問題