Skip to content

Instantly share code, notes, and snippets.

@baoo777
Created January 24, 2018 18:53
Show Gist options
  • Save baoo777/0f47ed214e31fe3de0280ace4f017c55 to your computer and use it in GitHub Desktop.
Save baoo777/0f47ed214e31fe3de0280ace4f017c55 to your computer and use it in GitHub Desktop.
ソースコードを文字列変数に格納
' /////////////////////////////////////////////////////////////////////////////////////
' //#名称 SrcToString
' //
' //#概要
' //
' //#引数 無し
' //
' //#戻値 無し
' //
' //#解説
' //
' //#履歴 2013/06/01
' // Coded by YASUTADA OOBA
' //
' /////////////////////////////////////////////////////////////////////////////////////
Private Sub SrcToString()
Dim vbComp As VBComponent
Dim strSrc() As String
Dim lngSt_RW As Long
Dim lngEd_RW As Long
Dim lngSt_CL As Long
Dim lngEd_CL As Long
Dim str As String
Dim lngInt As Long
'現在選択された位置を取得
Application.VBE.ActiveCodePane.GetSelection lngSt_RW, lngSt_CL, lngEd_RW, lngEd_CL
'Undoに使用
Debug.Print Application.VBE.ActiveCodePane.CodeModule.Lines(lngSt_RW, lngEd_RW - lngSt_RW)
'ソースコードをstrSouceに格納するコードを生成
strSrc = Split(Application.VBE.ActiveCodePane.CodeModule.Lines(lngSt_RW, lngEd_RW - lngSt_RW), vbCrLf)
For i = 0 To UBound(strSrc)
If str = "" Then
str = vbTab & "Dim strSource As String" & vbCrLf & vbTab & "strSource = """ & Replace(strSrc(i), """", """""")
ElseIf i Mod 24 = 0 Then
str = str & """ & vbCrLf" & vbCrLf & vbTab & "strSource = strSource & """ & Replace(strSrc(i), """", """""")
Else
str = str & """ & vbCrLf & _" & vbCrLf & vbTab & String(12, " ") & """" & Replace(strSrc(i), """", """""")
End If
Next i
'現在選択された位置を削除して変換文字列を挿入
Application.VBE.ActiveCodePane.CodeModule.DeleteLines lngSt_RW, lngEd_RW - lngSt_RW
Application.VBE.ActiveCodePane.CodeModule.InsertLines lngSt_RW, str
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment