Тема: VBS + VBA Запуск макроса в Excel
Внутри скрипта VBS есть вот такой код:
'===================================
i = objExcel.VBE.ActiveVBProject.VBComponents.Count
objExcel.VBE.ActiveVBProject.VBComponents.Add 1
Set objModule = objExcel.VBE.ActiveVBProject.VBComponents.Item(i + 1)
With objModule.CodeModule
.InsertLines 1, "Sub TestSub()"
.InsertLines 2, " Cells.Select"
.InsertLines 3, " Selection.NumberFormat = ""@"""
.InsertLines 4, " Range(""A1:Q1"").Select"
.InsertLines 5, " With Selection"
.InsertLines 6, " .HorizontalAlignment = xlGeneral"
.InsertLines 7, " .VerticalAlignment = xlCenter"
.InsertLines 8, " .WrapText = True"
.InsertLines 9, " .Orientation = 0"
.InsertLines 10, " .AddIndent = False"
.InsertLines 11, " .IndentLevel = 0"
.InsertLines 12, " .ShrinkToFit = False"
.InsertLines 13, " .ReadingOrder = xlContext"
.InsertLines 14, " .MergeCells = False"
.InsertLines 15, " End With"
.InsertLines 16, " Selection.Borders(xlDiagonalDown).LineStyle = xlNone"
.InsertLines 17, " Selection.Borders(xlDiagonalUp).LineStyle = xlNone"
.InsertLines 18, " Selection.Borders(xlEdgeLeft).LineStyle = xlNone"
.InsertLines 19, " Selection.Borders(xlEdgeTop).LineStyle = xlNone"
.InsertLines 20, " With Selection.Borders(xlEdgeBottom)"
.InsertLines 21, " .LineStyle = xlContinuous"
.InsertLines 22, " .ColorIndex = 0"
.InsertLines 23, " .TintAndShade = 0"
.InsertLines 24, " .Weight = xlThin"
.InsertLines 25, " End With"
.InsertLines 26, " Selection.Borders(xlEdgeRight).LineStyle = xlNone"
.InsertLines 27, " Selection.Borders(xlInsideVertical).LineStyle = xlNone"
.InsertLines 28, " Selection.Borders(xlInsideHorizontal).LineStyle = xlNone"
.InsertLines 29, " Range(""A1"").Select"
.InsertLines 30, " End Sub"
End With
objExcel.Application.Run "TestSub"
'===================================
Уважаемые, подскажите, как текст VBA кода подгрузить из текстового файла?