VBA String compare in Mac

If you use equal comparison with strings, that contain all none ASCII characters in Mac Excel VBA 2011, then it will be always true if the strings have the same length:
Word1=word2 is always returns TRUE if len(word1)=len(word2)
To avoid this used strcomp(word1,word2,vbtextcompare) function stead!

Use Find object to manipulate all appearances of a text of a document

Using Find method of Select object is very effective way to change all appearance of a text in a document. For example you may want to capitalize all the first case after ” in the document. Below is pseudo code to demo it:

Sub convertToUppercases() 
   'Goto start of the document 
    Selection.HomeKey Unit:=wdStory 
    switchCases False 
End Sub 
Sub convertToLowercases() 
    'Goto start of the document 
     Selection.HomeKey Unit:=wdStory 
     switchCases True 
End Sub 

Sub switchCases(ByVal bToLowerCase As Boolean) 
    Dim sText As String 
    Dim lCount As Long 
    Selection.Find.ClearFormatting 'Clear current find  
    With Selection.Find  
        .Text = <put some text need to be found here>   
        .Replacement.Text = ""   
        .Forward = True   
        .Wrap = wdFindContinue   
        .Format = True   
        .MatchCase = False   
        .MatchWholeWord = False   
        .MatchAllWordForms = False   
        .MatchSoundsLike = False   
        .MatchWildcards = True   
    End With    
        If Selection.Find.Found Then     
            if bToLowerCase then     
                <put the code need to be done here>     
                <put the code need to be done here>     
            end if     
        end if     
    Loop Until Not Selection.Find.Found     
End Sub

Add picture to bookmark

Sub UpdateBookmarkedImage(BmkNm As String, NewTxt As String)
Dim BmkRng As Range
With ActiveDocument
  If .Bookmarks.Exists(BmkNm) Then
    Set BmkRng = .Bookmarks(BmkNm).Range
    If  BmkRng.InlineShapes.Count >0 then 
    End if
    BmkRng.InlineShapes.AddPicture FileName:=NewTxt
    .Bookmarks.Add BmkNm, BmkRng
  End If
End With
Set BmkRng = Nothing
End Sub

Access a javascript variable from within AppleScript

The is a easy way to access any variable in  javascript from applescript by using browser’s window title or status. This is very important when you want to retrieve something from web page and parsing result of curl is too complicated. Bellow is an example  to do so with Google Chrome to get web page element with id=’MyDataToGetFromPage':

set sUrl to "http://www.someserver.com"
tell application "Google Chrome"
   set oTab to active tab of window 1
   set sResult to ""

   activate oTab
   set oTab's URL to sUrl
   set lDelay to 1
   repeat while oTab is loading and lDelay < 20
      delay 0.1
      set lDelay to lDelay + 1
   end repeat
   tell oTab
      set sMyJava to "if (document.getElementById(\"MyDataToGetFromPage\")) {" & linefeed & "document.title ='Title: ' + document.getElementById(\"MyDataToGetFromPage\").innerHTML;} else {document.title='Can not found data with id :MyDataToGetFromPage';}"
      execute javascript sMyJava
      set sResult to sResult & title of oTab
   end tell
   return sResult
end tell

Add links to cells with VBA

Sub addLinks()

‘ Converts each cell text of a selected range into a working hyperlink
For Each xCell In Selection
ActiveSheet.Hyperlinks.Add Anchor:=xCell, Address:=xCell.Formula
Next xCell

End Sub

CIA – Computer Industry Acronyms

CD-ROM: Consumer Device, Rendered Obsolete in Months
PCMCIA: People Can’t Memorize Computer Industry Acronyms
ISDN: It Still Does Nothing
SCSI: System Can’t See It
MIPS: Meaningless Indication of Processor Speed
DOS: Defunct Operating System
WINDOWS: Will Install Needless Data On Whole System
OS/2: Obsolete Soon, Too
PnP: Plug and Pray
APPLE: Arrogance Produces Profit-Losing Entity
IBM: I Blame Microsoft
MICROSOFT: Most Intelligent Customers Realize Our Software Only Fools Teenagers
COBOL: Completely Obsolete Business Oriented Language
LISP: Lots of Insipid and Stupid Parentheses
MACINTOSH: Most Applications Crash; If Not, The Operating System Hangs
AAAAA: American Association Against Acronym Abuse.
WYSIWYMGIYRRLAAGW: What You See Is What You Might Get If You’re Really Really Lucky And All Goes Well.

IT guru


Get every new post delivered to your Inbox.