Skip to content

Instantly share code, notes, and snippets.

@froop
Created May 9, 2011 15:28
Show Gist options
  • Select an option

  • Save froop/962737 to your computer and use it in GitHub Desktop.

Select an option

Save froop/962737 to your computer and use it in GitHub Desktop.
[Excel] Java変数名風に変換するマクロ
'単語を「_」(アンダーバー)で連結している文字列を
'Java変数名風に変換します。
'「_」の次の文字を大文字にし、それ以外を小文字にします。
'例)to_java_name→toJavaName
'セルに以下のように数式として記述することで使用できます。
'例)=ToJavaName(A1)
Function ToJavaName(ByVal Name As String)
Dim NewName As String
Dim I As Integer
Name = LCase(Name)
NewName = ""
For I = 1 To Len(Name)
Dim Char As String
Dim NewChar As String
Char = Mid(Name, I, 1)
If Char = "_" Then
I = I + 1
Char = Mid(Name, I, 1)
NewChar = UCase(Char)
Else
NewChar = Char
End If
NewName = NewName + NewChar
Next
ToJavaName = NewName
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment