Giter Club home page Giter Club logo

vbaunicodetools's Introduction

VBAUnicodeTools

Tools for working with Unicode in the VB Editor

This repository contains a standard VBA module ProgrammingTools.bas and associated userforms for working with Unicode text in the VB Editor (VBE).

References

The code in these VBA modules references the following libraries.

  1. Microsoft VBScript Regular Expressions 5.5
  2. Microsoft Visual Basic for Applications Extensibility 5.3.

Main Features

There are two main subroutines to help you edit VBA code that deals with Unicode characters outside the ASCII range to circumvent VBE's lack of support for Unicode.

  1. Public Sub PromptToInsertUnicodeStringIntoVBA()
  2. Public Sub DisplayUnicodeFromVBACode()

Public Sub PromptToInsertUnicodeStringIntoVBA()
Place the cursor wherever you want to insert VBA code for a string containing Unicode characters outside the ASCII range, then run PromptToInsertUnicodeStringIntoVBA. The sub will show a userform with a single textbox that you can type into. Press the "Convert & Insert" button to convert the contents of that textbox to corresponding VBA code and insert it where you placed your cursor in the VB editor.

Screen capture of PromptToInsertUnicodeStringIntoVBA in action

Public Sub DisplayUnicodeFromVBACode()
Select VBA code in the VB editor with Unicode characters hard-coded hexidecimal or decimal codepoints inside ChrW$ or ChrW calls, then run DisplayUnicodeFromVBACode. The sub will show a userform with a single textbox containing those ChrW$/ChrW calls replaced by the Unicode characters they represent.

Screen capture of DisplayUnicodeFromVBACode in action

Additional Features

There are a few other utility functions for processing Unicode text in VBA.

  • Public Function MsgBoxW(Prompt As String, Optional Buttons As VbMsgBoxStyle = vbOKOnly, Optional Title As String = "Microsoft PowerPoint") As VbMsgBoxResult
    A wide version of MsgBox, adapted from forum post by John_w at https://www.mrexcel.com/board/threads/vba-display-foreign-character-code.1142510/post-5536387.

  • Public Sub ShowCharForCodePoint()
    Shows a message box containing the character associated with the codepoint selected in the VB editor. Assumes the selection contains only a VBA int/long literal.

  • Public Function GetSelectedVBACode() As String
    Returns a string containing the text currently selected in the VB editor.

  • Public Function ConvertUnicodeTextToVBACode(ByRef text As String) As String
    Takes a string of ordinary text and returns a string with that text converted to corresponding VBA string literals, VBA constants, and calls to ChrW$, all concatenated together. VBA line continuations and CRLFs are inserted whenever any line in the output would exceed 512 characters (Adjustable by changing the private constant VBA_MAX_LINE_LENGTH declared at the top of the module. Actual VBE max line length is 1024 characters.).

  • Public Function AscWLong(char As String) As Long
    Wrapper around AscW to make sure that all codepoints returned are positive. (Because VBA doesn't have unsigned data types!)

vbaunicodetools's People

Contributors

baker-ling avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

vb6hobbyst7

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.