VBA String compare in Mac
Posted: 11/07/2012 Filed under: Excel Leave a comment »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
Posted: 05/06/2012 Filed under: MS Office, Word | Tags: macro, Microsoft+office, office automation, User-defined function, vba, Visual Basic for Applications Leave a comment »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
Do
Selection.Find.Execute
If Selection.Find.Found Then
if bToLowerCase then
<put the code need to be done here>
else
<put the code need to be done here>
end if
end if
Loop Until Not Selection.Find.Found
End Sub
Add picture to bookmark
Posted: 30/04/2012 Filed under: Word | Tags: bookmark, inlineshapes, ms word, picture, vba Leave a comment »
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
BmkRng.InlineShapes(1).Delete
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
Posted: 04/04/2012 Filed under: Scripts Leave a comment »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"
activate
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
Posted: 04/04/2012 Filed under: Excel, MS Office | Tags: enterprise-it, excel, macro, Microsoft, Microsoft Excel, Microsoft+office, office automation, vba, Visual Basic for Applications Leave a comment »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
Posted: 28/03/2012 Filed under: IT hurmors Leave a comment »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.
