Sub Example()
Dim myRange
Dim result
Dim Run As Long
For Run = 1 To 3
Select Case Run
Case 1
result = "=SUM(A1:A100)"
Case 2
result = "=SUM(A1:A300)"
Case 3
result = "=SUM(A1:A25)"
End Select
ActiveSheet.range("B" & Run) = result
Next Run
End Sub
(function() {
for (let run = 1; run <= 3; run++) {
var result = "";
switch (run) {
case 1:
result = "=SUM(A1:A100)";
break;
case 2:
result = "=SUM(A1:A300)";
break;
case 3:
result = "=SUM(A1:A25)";
break;
default:
break;
}
Api.GetActiveSheet().GetRange("B" + run).Value = result;
}
})();
(function() {
Api.GetActiveSheet().GetRange("C4").SetValue("Hello world");
})();
Sub example()
Cells(4, 3) = "Hello world"
End Sub
(function() {
Api.GetActiveSheet().GetRange("B3").SetFillColor(Api.CreateColorFromRGB(0, 0, 250));
})();
Sub example()
Range("B3").Interior.Color = RGB(0, 0, 250)
End Sub
(function() {
Api.GetActiveSheet().GetRange("B4").SetFontColor(Api.CreateColorFromRGB(255, 0, 0));
})();
Sub example()
Range("B4").Font.Color = RGB(255, 0, 0)
End Sub
Sub example()
Range("B4").Font.Color = RGB(255, 0, 0)
End Sub
(function() {
Api.GetActiveSheet().GetRange("A2").SetBold(true);
})();
Sub example()
Range("A2").Font.Bold = True
End Sub
(function()
{
Api.GetActiveSheet().GetRange("A1:B3").Merge(true);
})();
Sub example()
Range("A1:B3").Merge
End Sub
(function()
{
Api.GetActiveSheet().GetRange("C5:D10").UnMerge();
})();
Sub example()
Range("C5:D10").UnMerge
End Sub
(function()
{
Api.GetActiveSheet().SetColumnWidth(1, 25);
})();
Sub example()
Columns("B").ColumnWidth = 25
End Sub
(function()
{
Api.GetActiveSheet().FormatAsTable("A1:D10");
})();
Sub example()
Sheet1.ListObjects.Add(xlSrcRange, Range("A1:D10"), , xlYes).Name = "myTable1"
End Sub
((function()
{
Api.GetActiveSheet().AddChart("'Sheet1'!$C$5:$D$7", true, "bar", 2, 105 * 36000, 105 * 36000, 0, 0, 9, 0);
})();
Sub example()
With ActiveSheet.ChartObjects.Add(Left:=300, Width:=300, Top:=10, Height:=300)
.Chart.SetSourceData Source:=Sheets("Sheet1").Range("C5:D7")
End With
End Sub
(function ()
{
// Получаем активный лист
var activeSheet = Api.GetActiveSheet();
// Минимальный индекс строки
var indexRowMin = 0;
// Максимальный индекс строки
var indexRowMax = 1048576;
// Столбец 'A'
var indexCol = 0;
// Индекс строки для поиска пустой ячейки
var indexRow = indexRowMax;
for (; indexRow >= indexRowMin; --indexRow) {
// Получаем ячейку
var range = activeSheet.GetRangeByNumber(indexRow, indexCol);
// Проверяем значение
if (range.GetValue() && indexRow !== indexRowMax) {
range = activeSheet.GetRangeByNumber(indexRow + 1, indexCol);
range.Select();
break;
}
}
})();
Sub example()
Range("A" & Rows.Count).End(xlUp).Offset(1).Select
End Sub
(function()
{
var oDocument = Api.GetDocument();
var oParagraph = Api.CreateParagraph();
oParagraph.AddText("Hello world!");
oDocument.InsertContent([oParagraph]);
})();
Sub example()
Selection.TypeText Text:="Hello world!"
End Sub
(function()
{
var sCurPair = "USD_EUR";
function formatDate(d) {
var month = '' + (d.getMonth() + 1),
day = '' + d.getDate(),
year = d.getFullYear();
if (month.length < 2)
month = '0' + month;
if (day.length < 2)
day = '0' + day;
return [year, month, day].join('-');
}
function previousWeek(){
var today = new Date();
var prevweek = new Date(today.getFullYear(), today.getMonth(), today.getDate() - 7);
return prevweek;
}
var sDate = formatDate(previousWeek());
var sEndDate = formatDate(new Date());
var apiKey = 'ваш_ключ_от_API';
var sUrl = 'https://free.currconv.com/api/v7/convert?q='
+ sCurPair + '&compact=ultra' + '&date=' + sDate + "&endDate=" + sEndDate + '&apiKey=' + apiKey;
var xmlHttp = new XMLHttpRequest();
xmlHttp.open("GET", sUrl, false);
xmlHttp.send();
if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
var oData = JSON.parse(xmlHttp.responseText);
for(var key in oData) {
var sheet = Api.GetSheet("Sheet1");
var oRange = sheet.GetRangeByNumber(0, 1);
oRange.SetValue(key);
var oDates = oData[key];
var nRow = 1;
for(var date in oDates) {
oRange = sheet.GetRangeByNumber(nRow, 0);
oRange.SetValue(date);
oRange = sheet.GetRangeByNumber(nRow, 1);
oRange.SetValue(oDates[date]);
nRow++;
}
}
}
})();
Sub example()
' ' Этот пример не имеет прямого аналога в VBA и требует стороннего API
End Sub
(function ()
{
let timerId = setInterval(function(){
Api.asc_calculate(Asc.c_oAscCalculateType.All);
var oWorksheet = Api.GetActiveSheet();
oWorksheet.GetRange("F2").SetValue("Average");
oWorksheet.GetRange("G2").SetValue("=AVERAGE(B2:B80)");
}, 1000);
})();
Sub example()
Application.OnTime Now + TimeValue("00:00:01"), "RecalculateValues"
End Sub
Sub RecalculateValues()
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets("Sheet1")
ws.Calculate
ws.Range("F2").Value = "Average"
ws.Range("G2").Formula = "=AVERAGE(B2:B80)"
' 'Reschedule the recalculation
Application.OnTime Now + TimeValue("00:00:01"), "RecalculateValues"
End Sub
(function()
{
var activeSheet = Api.GetActiveSheet();
var indexRowMax = 1048576;
var indexColMax = 16384; // Максимальное количество столбцов в Excel
// Отобразить все строки
for (let i = 0; i < indexRowMax; i++) {
activeSheet.GetRows(i + 1).SetHidden(false);
}
// Отобразить все столбцы
for (let j = 0; j < indexColMax; j++) {
activeSheet.GetColumns(j + 1).SetHidden(false);
}
var newRange = activeSheet.GetRange("A1");
newRange.SetValue("All the rows and columns are unhidden now");
})();
Sub UnhideAllRowsAndColumns()
Cells.EntireRow.Hidden = False
Cells.EntireColumn.Hidden = False
Range("A1").Value = "All the rows and columns are unhidden now"
End Sub
(function()
{
var oPresentation = Api.GetPresentation();
var slideCount = oPresentation.GetSlideCount(); // Получаем количество слайдов в презентации
for (let i = 0; i < slideCount; i++) {
var oSlide = oPresentation.GetSlideByIndex(i);
var aShapes = oSlide.GetAllShapes();
for (let j = 0; j < aShapes.length; j++) {
aShapes[j].Delete();
}
}
})();
Sub RemoveShapes()
Dim slide As slide
Dim shape As shape
For Each slide In ActivePresentation.Slides
For Each shape In slide.Shapes
shape.Delete
Next shape
Next slide
End Sub
(function()
{
function generate() {
let key = '';
const data = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' +
'abcdefghijklmnopqrstuvwxyz0123456789';
for (let i = 1; i <= 12; i++) {
let index = Math.floor(Math.random() * data.length);
key += data.charAt(index);
}
return key;
}
const id = generate();
const oDocument = Api.GetDocument();
const oParagraph = Api.CreateParagraph();
oParagraph.AddText(id);
oDocument.InsertContent([oParagraph], { "KeepTextOnly": true });
})();
Sub InsertUniqueId()
Dim uniqueId As String
uniqueId = GenerateUniqueId()
Sub InsertUniqueId()
Dim uniqueId As String
uniqueId = GenerateUniqueId()
Dim para As Paragraph
Set para = ActiveDocument.Paragraphs.Add
para.Range.Text = uniqueId
End Sub
Function GenerateUniqueId() As String
Dim i As Integer
Dim key As String
Dim data As String
data = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
For i = 1 To 12
key = key & Mid(data, Int((Len(data) * Rnd) + 1), 1)
Next i
GenerateUniqueId = key
End Function