Skip to content

Instantly share code, notes, and snippets.

Now let's actually look at the code originally investigated in the author's original video ported to VBA

public sub run()
  while true
    Dim path as string
    while (path = requestedUrls.poll()) != null    
      downloads.add(new DownloadState(path))
    wend
    if not me.connectionDisabled then

Dim iterator as ListIterator

@sancarn
sancarn / UpdatingSharepointRESTExample.js
Created November 29, 2022 20:25
Simple script to update sharepoint using the REST API
//Note: When porting `Authorization: "Bearer " + accessToken` will also be required in all headers!
/*
* Get all fields of a list
* @param {string} site - Url of site
* @param {string} list - Title of list
* @example await getListFields("https://myServer.sharepoint.com/sites/my/sharepoint/site", "My list name")
* @docs https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/working-with-lists-and-list-items-with-rest
*/
async function getListFields(site, list){
'Example CSV:
' Column1,Column2,Result
' 1,2,
' 2,3,
' 3,5,
'Results in:
' Column1,Column2,Result
' 1,2,2
' 2,3,6
' 3,5,15
@sancarn
sancarn / VBA-OfficeJS bridge test.EXCEL.yaml
Last active January 3, 2022 23:36
A test to attempt to listen to VBA changes to the customXMLParts structure.
name: VBA-OfficeJS bridge test
description: A test to attempt to listen to VBA changes to the customXMLParts structure.
host: EXCEL
api_set: {}
script:
content: |+
/* VBA USAGE EXAMPLE
'Example from VBA:
'Requires JsBridge from here: https://github.com/sancarn/VbaJsBridge
'ScriptLab test can be downloaded here: https://gist.github.com/sancarn/b974b650f4b451ff2de51861af1671b1
@sancarn
sancarn / Blank snippet.EXCEL.yaml
Created January 3, 2022 19:43
Create a new snippet from a blank template.
name: Blank snippet
description: Create a new snippet from a blank template.
host: EXCEL
api_set: {}
script:
content: |
type IXMLWatcherListener = (e: any) => void
class XMLWatcher {
private interval: number;
private listeners: IXMLWatcherListener[];
@sancarn
sancarn / Deref.bas
Last active December 20, 2021 15:00
VBA Deref/Dereference objects (Convert from ObjPtr to Object)
#If VBA7 Then
Private Declare PtrSafe Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As LongPtr)
Private Declare PtrSafe Sub ZeroMemory Lib "kernel32" Alias "RtlZeroMemory" (Destination As Any, ByVal Length As Long)
#Else
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Declare Sub ZeroMemory Lib "kernel32" Alias "RtlZeroMemory" (Destination As Any, ByVal Length As Long)
#End If
Public Sub test()
Debug.Print Deref(ObjPtr(Application)).Name
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
END
Attribute VB_Name = "SAPECC"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'{F9} - Jump to first form value
@sancarn
sancarn / 01. Infinite acceleration loop.js
Last active September 9, 2021 22:52
Open AI Codex fun
/* Make screen a canvas */
var canvas = document.createElement('canvas');
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
document.body.appendChild(canvas);
/* remove scroll bars */
document.body.style.overflow = 'hidden';
/* add a circle to the canvas */
@sancarn
sancarn / Proxy.rb
Last active February 17, 2021 11:08
=begin
=================================
PROXY VERSION 3
=================================
DEFINITION:
I want a simple wrapper which will wrap the Application class and down.
Criterium:
@sancarn
sancarn / How to use a function pointer in VBA.md
Created December 30, 2020 12:14
How to use a function pointer in VBA by Akihito Yamashiro

VB6 and VBA come with no support for function pointers.

Also, when you wish to execute a function in a dll using the Declare function, you can only call functions created by the Steadcall calling conversation.

These constraints can be avoided by using the DispCallFunc API. The DispCallFunc is widely used in VB6 when erasing the history of IE. Although the DispCallFunc is known as API for calling the IUnknown interface, in fact, you can also perform other functions other than COM by passing the NULL to the first argument.

As explained in the http://msdn.microsoft.com/en-us/library/ms221473(v=vs.85).aspx , the DispCallFunc argument is as follows.