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 
        BmkRng.InlineShapes(1).Delete
    End if
    BmkRng.InlineShapes.AddPicture FileName:=NewTxt
    .Bookmarks.Add BmkNm, BmkRng
  End If
End With
Set BmkRng = Nothing
End Sub
Advertisements

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"
   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

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