-
Notifications
You must be signed in to change notification settings - Fork 0
/
microsoft.html
657 lines (583 loc) · 18.8 KB
/
microsoft.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Microsoft</title>
<style>body{font-size: 12px}code,pre{margin:0;padding:0;}
body>pre{white-space:pre-wrap;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space: -o-pre-wrap;word-wrap:break-word;}
</style>
</head>
<body>
<h1>Excel, JavaScript, VBA, VBScript</h1>
<table border="1" width="150%">
<tbody>
<tr>
<td>Excel</td>
<td>Javascript</td>
<td >
<pre><code>VBA/VB6(.vb)
Alt+F11, Alt+I, M
Insert>Module | Accesses macros and code</code></pre>
</td>
<td>
<pre><code>VBScript(.vbs or .vbe)
crscript wscript</code></pre>
</td>
</tr>
<tr>
<td>Global var | You can name cells by clicking
<p>the Name Box (that thing next to the formula bar</p>
<p>which says "A1" for example) and typing a name</p>
<p>Stored array | A1:A2<br>
Array constant | INDEX({1,2,3},1)<br>
multiline string Alt+Enter</p>
</td>
<td>
<pre>
<code>var a = [1, 2]
const a = [1, 2];// not exactly the same thing but close
var s = "testing\
1\
2";
a[1][2];
"{0}".replace("0","testing")<br>
</code></pre>
</td>
<td>Range("MyBook.xls!MyRange").Font.Italic = True
<p>Sub ClearRange(): Application.Goto Reference:="MyBook.xls!MyRange" : Selection.ClearContents : End Sub</p>
<p>Public globalv<br>
Sub m(): globalv = 1: End Sub: m</p>
<pre>TypeOf 1 Is Integer
</pre>
<pre><code>CStr(Environ("USERPROFILE"))
Replace("testing", "{0}", "0")<br>
' no multiline string support
</code></pre>
</td>
<td>
<pre><code>
Const Constant = Value
x = CInt("1")
' CBool, CByte, CCur, CDate, CDbl, CInt, CLng, CSng, CStr
WScript.Echo TypeName(x)</code></pre>
</td>
</tr>
<tr>
<td>
=DATE(1999,1,1)
</td>
<td><pre>Form_Load = function(){
x = "Hello World"
alert(x);
}
Form_Load()
getFullYear() Get the year as a four digit number (yyyy)
getMonth() Get the month as a number (0-11)
getDate() Get the day as a number (1-31)
getHours() Get the hour (0-23)
getMinutes() Get the minute (0-59)</pre>
</td>
<td>
<pre><code>Private Sub Form_Load()
Dim x As String ' type optional
x = "Hello World"
MyStr = Format(Time, "Long Time")
MsgBox x
End Sub
Form_Load()
Format(#1/27/1993#, "yyyy-MM-dd Hh:mm:Ss")
MyStr = Format(Time, "Long Time")
MyStr = Format(Date, "Long Date")
MyStr = Format(MyTime, "h:m:s") ' Returns "17:4:23".
MyStr = Format(MyTime, "hh:mm:ss am/pm") ' Returns "05:04:23 pm".
MyStr = Format(MyTime, "hh:mm:ss AM/PM") ' Returns "05:04:23 PM".
MyStr = Format(MyDate, "dddd, mmm d yyyy") ' Returns "Wednesday, Jan 27 1993".
' If format is not supplied, a string is returned.
MyStr = Format(23) ' Returns "23".
' Function can return value sub can not
' User-defined formats.
MyStr = Format(5459.4, "##,##0.00") ' Returns "5,459.40".
MyStr = Format(334.9, "###0.00") ' Returns "334.90".
MyStr = Format(5, "0.00%") ' Returns "500.00%".
MyStr = Format("HELLO", "<") ' Returns "hello".
MyStr = Format("This is it", ">") ' Returns "THIS IS IT".
</code></pre>
</td>
<td>
<pre>
<!doctype html><meta http-equiv="x-ua-compatible" content="IE=10">
<script type="text/vbscript">
msgbox "Hello World!"
</script>
Function CalculateArea(Radius)
CalculateArea = Radius * Radius * 3.14159
End Function</pre>
</td>
</tr>
<tr>
<td>
=A3:A4=A3:A4
</td>
<td>
JavaScript Numbers are Always 64-bit Floating Point
<br>
</td>
<td>
<pre>'Byte,Integer,Long,Single,Double,Currency,Decimal,
'String(n),Date,Boolean,Object,Variant
'requires you to define variable if explicit
<code>Option Explicit On
Dim a, b, c, d, m, n As Integer
Const MyInteger As Integer = 42
Dim x, y As Double
Dim, Set, RefBy, ByVal</code></pre>
</td>
<td></td>
</tr>
<tr>
<td></td>
<td>result = 5 < 10 ? "Yes it is" : "No it isn't"</td>
<td>
<pre><code>result = IIf(5 < 10, "Yes it is", "No it isn'")'</code></pre>
</td>
<td></td>
</tr>
<tr>
<td></td>
<td>
<pre><code>var message = "",
count = 0;
if ( count == 0){
message = "There are no items";
} else if(count == 1){
message = "There is 1 item";
}else{
mesage = "There are "+count+ " items.";
}</code></pre>
</td>
<td>
<pre><code>Dim count As Integer = 0
Dim message As String
If count = 0 Then
message = "There are no items."
ElseIf count = 1 Then
message = "There is 1 item."
Else
message = "There are " & count & " items."
End If</code></pre>
</td>
<td ></td>
</tr>
<tr>
<td></td>
<td>&& || ^ ! <> && || ===</td>
<td>
<pre><code>And Or Xor Not <> = AndAlso OrElse
Is</code></pre>
</td>
<td></td>
</tr>
<tr>
<td></td>
<td>For(var i = 0;i<2;i++){
<p> alert(i);</p>
<p>}</p>
</td>
<td>
<pre>Dim i as Integer
<code>For i = 0 To 2
MsgBox i
Next i
Dim i as Variant: i = 0
While i <
MsgBox i
i = i + 1
Wend
fruits = Array("apple", "orange", "cherries")
Dim fruitnames As Variant
For Each Item In fruits
fruitnames = fruitnames & Item & Chr(10)
Next
MsgBox fruitnames
Public Sub OnErrorDemo()
On Error GoTo ErrorHandler 'Dim x, y, z As Integer
x = 50
y = 0
z = x / y ' Divide by ZERO Error Raises
ErrorHandler: ' Error-handling routine.
Select Case Err.Number ' Evaluate error number.
Case 10 ' Divide by zero error
MsgBox ("You attempted to divide by zero!")
Case Else
MsgBox "UNKNOWN ERROR - Error# " & Err.Number & " : " & Err.Description
End Select
Resume Next
End Sub</code></pre>
</td>
<td >Dim i <br>
For i = 1 To 3<br>
MsgBox i<br>
Next </td>
</tr>
<tr>
<td></td>
<td>
<pre translate="no" dir="ltr" is-upgraded=""><code dir="ltr">debugger;<br>
</code></pre>
</td>
<td >
<pre><code>Stop</code></pre>
</td>
<td ></td>
</tr>
<tr>
<td></td>
<td></td>
<td >
<pre><code>N/A</code></pre>
</td>
<td ></td>
</tr>
<tr>
<td></td>
<td></td>
<td >
<pre><code>Function MyMax(ParamArray agrs())
End Function</code></pre>
</td>
<td ></td>
</tr>
<tr>
<td></td>
<td><code>function Class(){</code>
<p><code> alert("Init");</code></p>
<p><code>}</code></p>
<p><code>// Functions are like new objects</code></p>
<p><code>// No terminate fn</code></p>
<p><code>// types are like objects</code></p>
<p></p>
</td>
<td >
<pre><code>'Classes don't really have a syntax exactly
Private Sub Class_Initialize()
MsgBox "Init"
End Sub
Private Sub Class_Terminate()
MsgBox "Terminate"
End Sub
</code>Dim C As Class<br>
Set C = New Class<code>
'cpearson.com/excel/classes.aspx
Type Employee
Name As String
Salary As Double
End Type
Dim i As Employee
i.Name = "Joe Smith"
i.Salary = 40000</code></pre>
</td>
<td ></td>
</tr>
<tr>
<td></td>
<td>// LBound(a)==0 to UBound(a)==a.length</td>
<td >
<pre><code>Function Split1()
Dim strTest As String
Dim strArray() As String
Dim intCount As Integer
strTest = "Fred & Wilma & Barney & Betty"
strArray = Split(strTest, "&")
For intCount = LBound(strArray) To UBound(strArray)
MsgBox Trim(strArray(intCount))
Next
End Function
a = array("Red","Blue","Yellow")
b = join(a,"$")
</code></pre>
<pre>Sub OptionalArgs(i As String, Optional s As String = "init")
'MsgBox 1
End Sub<br>
</pre>
</td>
<td ></td>
</tr>
<tr>
<td></td>
<td>Shell = new ActiveXObject("WScript.Shell");<br>
DesktopPath = Shell.SpecialFolders("Desktop");<br>
link = Shell.CreateShortcut(DesktopPath + "\\test.lnk");<br>
// link.Arguments = "1 2 3";<br>
link.Description = "test shortcut";<br>
// link.HotKey = "CTRL+ALT+SHIFT+X";<br>
// link.IconLocation = "app.exe,1";<br>
link.TargetPath = "C:\\Program Files\\Mozilla Firefox\\firefox.exe";<br>
// link.WindowStyle = 3;<br>
// link.WorkingDirectory = "c:\\blah";<br>
link.Save();</td>
<td>' Set Shell = CreateObject("WScript.Shell")<br>
' DesktopPath = Shell.SpecialFolders("Desktop")<br>
' Set link = Shell.CreateShortcut(DesktopPath & "\test.lnk")<br>
' link.Arguments = "1 2 3"<br>
' link.Description = "test shortcut"<br>
' link.HotKey = "CTRL+ALT+SHIFT+X"<br>
' link.IconLocation = "app.exe,1"<br>
' link.TargetPath = "c:\blah\app.exe"<br>
' link.WindowStyle = 3<br>
' link.WorkingDirectory = "c:\blah"<br>
' link.Save</td>
<td></td>
</tr>
<tr>
<td></td>
<td>window.onload = function(){ alert("onload"); };
<p>document.getElementById("ComboBox1").onchange = function(){</p>
<p>aler("testing");</p>
<p>}</p>
<p>"1\"2" // double quotes</p>
</td>
<td>Sub WorkBook_Open()
<p> MsgBox "Open"</p>
<p>End Sub</p>
<p>Private Sub ComboBox1_Change()</p>
<p> MsgBox "testing"</p>
<p>End Sub</p>
<pre><code>"1" & Chr(34) & "2" </code></pre>
</td>
<td></td>
</tr>
<tr>
<td></td>
<td>
<p><a href="https://stackoverflow.com/q/13221922">https://stackoverflow.com/q/13221922</a></p>
</td>
<td>Worksheets(Array("Sheet1", "Sheet2", "Sheet4")).Copy
<p>With ActiveWorkbook </p>
<p> .SaveAs Filename:=Environ("TEMP") & "\New3.xlsx", FileFormat:=xlOpenXMLWorkbook </p>
<p> .Close SaveChanges:=False</p>
<p>End With</p>
<p>Sub Add_comment()</p>
<p>Dim cmt As String<br>
cmt = “My comment”</p>
<p>If ActiveCell.Comment Is Nothing Then<br>
ActiveSheet.Range(Application.ActiveCell.Address).AddComment cmt<br>
Else<br>
MsgBox “This cell already has a comment”<br>
End If</p>
<p>End Sub</p>
<p>Sub Delete_comment()</p>
<p>ActiveSheet.Range(Application.ActiveCell.Address).Comment.Delete</p>
<p>End Subo</p>
<p>' <a href="https://stackoverflow.com/questions/14822672/parsing-a-json-object-array-in-excel-vba">https://stackoverflow.com/questions/14822672/parsing-a-json-object-array-in-excel-vba</a></p>
<p><a href="https://stackoverflow.com/questions/6627652/parsing-json-in-excel-vba">' https://stackoverflow.com/questions/6627652/parsing-json-in-excel-vba</a></p>
<p><br>
</p>
</td>
<td></td>
</tr>
<tr>
<td></td>
<td><input id=button type=button>
<p>document.getElementById('button').onclick = function(){</p>
<p> ;</p>
<p>}</p>
<p>var favDrink = prompt("What's your favorite cocktail drink?", "Default");</p>
</td>
<td>
<p>Private Sub CommandButton1_Click()</p>
<p>Worksheets(1).Cells(1, 1) = VBAProject.UserForm1.TextBox1<br>
Worksheets(1).Cells(2, 1) = VBAProject.UserForm1.TextBox2</p>
<p>End Sub</p>
<p>UserForm1.Show</p>
</td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td>a = Split("Red $ Blue $ Yellow","$")<br>
For i = 0 to ubound(a)<br>
MsgBox i&" "&a(i)<br>
Next
<pre>Dim Arr() As Variant
Arr = Range("A1:B10")
Dim R As Long
Dim C As Long
For R = 1 To UBound(Arr, 1) ' First array dimension is rows.
For C = 1 To UBound(Arr, 2) ' Second array dimension is columns.
Debug.Print Arr(R, C)
Next C
Next R
</pre>
</td>
<td></td>
</tr>
<tr>
<td></td>
<td>
<pre><code>var TypeDictionary = {
0: 'vbEmpty',
1: 'vbNull',
2: 'vbInteger',
3: 'vbLong',
4: 'vbSingle',
5: 'vbDouble',
6: 'vbCurrency',
7: 'vbDate',
8: 'vbString',
9: 'vbObject',
10: 'vbError',
11: 'vbBoolean',
12: 'vbVariant',
13: 'vbDataObject',
17: 'vbByte'
};
var GetType = function() {
return TypeDictionary[arguments[0]];
};</code></pre>
</td>
<td></td>
<td>
<pre><code>Dim TypeDictionary
Set TypeDictionary = CreateObject("Scripting.Dictionary")
TypeDictionary.Add 0, "vbEmpty"
TypeDictionary.Add 1, "vbNull"
TypeDictionary.Add 2, "vbInteger"
TypeDictionary.Add 3, "vbLong"
TypeDictionary.Add 4, "vbSingle"
TypeDictionary.Add 5, "vbDouble"
TypeDictionary.Add 6, "vbCurrency"
TypeDictionary.Add 7, "vbDate"
TypeDictionary.Add 8, "vbString"
TypeDictionary.Add 9, "vbObject"
TypeDictionary.Add 10, "vbError"
TypeDictionary.Add 11, "vbBoolean"
TypeDictionary.Add 12, "vbVariant"
TypeDictionary.Add 13, "vbDataObject"
TypeDictionary.Add 17, "vbByte"
Public Function GetType(argument)
GetType = TypeDictionary.Item(VarType(argument))
End Function</code></pre>
</td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
<pre>
https://stackoverflow.com/questions/37758275/vba-looking-for-a-fast-way-to-highlight-every-other-row
<a href="https://stackoverflow.com/questions/26356672/how-to-access-sql-server-from-vba-in-a-non-deprecated-way">https://stackoverflow.com/questions/26356672/how-to-access-sql-server-from-vba-in-a-non-deprecated-way
</a><a href="https://stackoverflow.com/questions/2050505/way-to-run-excel-macros-from-command-line-or-batch-file">https://stackoverflow.com/questions/2050505/way-to-run-excel-macros-from-command-line-or-batch-file</a>
VB.NET, VBA and VBScript are all different langauges. Unlike VBA, VBScript has only one data type — Variant, so you don't specify the data type when declaring a variable.
<a href="./$.xlsm">$.xlsm</a>
Excel is stupid
- you can't put multiple links in the same cell
- you can't put images(only links) in a cell, although you can attach it as a comments background
- it is only scriptable with
- VBA, VB.NET, C++, Powershell
- Mathematica
- http://xlwings.org
- https://datanitro.com/pricing
https://tduhameau.wordpress.com
https://excelk.com/
http://excelmatters.com
http://www.automateexcel.com/functions
http://www.cpearson.com/Excel/ListFirstAndLastElements.aspx
http://businessfunctions.com/index.php?pageno=156
http://www.techonthenet.com/excel/formulas/pmt.php
<a href="https://www.tutorialspoint.com/vbscript/">https://www.tutorialspoint.com/vbscript/
</a><a href="https://www.automateexcel.com/vba-code-library">https://www.automateexcel.com/vba-code-library</a>
<a href="https://blogs.harvard.edu/rprasad/2014/06/16/reading-excel-with-python-xlrd/">Reading Excel with Python</a> python-excel.org
Excel Solver
f2 - Object Browser
.Cells(0,0) ' -1 -1 cell
Named Ranges Excel allows for stuff like Sum(Students)
Access macro actions represent only a subset of the commands available in VBA.
Redim Preserve ' resize array
VBA: Visual Basic for Applications Different Versions
VSTO: Visual Studio Tools for Office
VSTA: Visual Studio Tools for Applications
VS.NET: Visual Studio.NET – currently version 2003. 2005 due next month.
IDE: Integrated Development Environment (in Excel, this is the visual basic editor)
Set objHTTP = CreateObject("MSXML2.ServerXMLHTTP")
URL = "http://www.somedomain.com"
objHTTP.Open "POST", URL, False
objHTTP.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
objHTTP.send("")
Dim fso as Object
Set fso = CreateObject("Scripting.FileSystemObject")
Dim oFile as Object
Set oFile = FSO.CreateTextFile(".\test2.txt")
oFile.WriteLine "test"
oFile.Close
Set fso = Nothing
Set oFile = Nothing
HouseCalc 99800, 43100
Call HouseCalc(380950, 49500)
named arguments
MsgBox Title:="Task Box", Prompt:="Task Completed!"<br>
ActiveSheet.Range("A1").Select<br>
ActiveCell.CurrentRegion.Copy<br>
ActiveSheet.Range("A2").Select<br>
ActiveSheet.Paste
</pre>
<pre>Option Explicit
'code loosely based on 'http://stackoverflow.com/questions/5773683/excel-vba-parsed-json-object-loop
'actual code from https://stackoverflow.com/questions/23580472/calling-javascript-files-from-vba
'code allows you to run JScript code in Excel/VBA
'Tools->References->
'MSScriptControl; Microsoft Script Control 1.0; {0E59F1D2-1FBE-11D0-8FF2-00A0D10038BC}; C:\Windows\SysWOW64\msscript.ocx
Private moScriptEngine As ScriptControl
Public Property Get ScriptEngine()
If moScriptEngine Is Nothing Then
Set moScriptEngine = New ScriptControl
moScriptEngine.Language = "JScript"
'moScriptEngine.AllowUI = True
End If
Set ScriptEngine = moScriptEngine
End Property
Do While True
WScript.StdOut.Write("$ ")
line = Trim(WScript.StdIn.ReadLine)
If LCase(line) = "exit" Then Exit Do
On Error Resume Next
Execute line
If Err.Number <> 0 Then
WScript.StdErr.WriteLine Err.Description
End If
On Error Goto 0
Loop
Public Sub AddJSFile(ByVal sJSFilename As String)
Debug.Assert LCase$(Right$(sJSFilename, 3)) = ".js"
Dim fso As Object 'Scripting.FileSystemObject
Set fso = VBA.CreateObject("Scripting.FileSystemObject")
Debug.Assert fso.FileExists(sJSFilename)
Dim fil As Object 'Scripting.File
Set fil = fso.GetFile(sJSFilename)
Dim ins As Object 'Scripting.TextStream
Set ins = fil.OpenAsTextStream(1) '1=ForReading
Dim sCode As String
sCode = ins.ReadAll
ins.Close
Set ins = Nothing
Set fil = Nothing
Set fso = Nothing
Debug.Assert Len(sCode) > 0
ScriptEngine.AddCode sCode
End Sub
'!Fellow StackOverflow users, press F5 on this Sub as this is entry point!
Function JS(ByVal s As String)
AddJSFile ActiveWorkbook.Path & "\testing.js"
JS = ScriptEngine.Eval(s)
End Function
</pre>
<pre><code>PS = Application.PathSeparator
</code></pre>
<pre><code>CStr(Environ("USERPROFILE") & "\Application Data")</code></pre>
<pre><code>process.env[(process.platform == 'win32') ? 'USERPROFILE' : 'HOME']</code></pre>
</body>
</html>