daily pastebin goal
17%
SHARE
TWEET

replace link to html tag IMG (MS word)

tolikpunkoff Jan 11th, 2018 (edited) 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Sub InsertIMG()
  2.  
  3.     'replace image address to IMG HTML tag
  4.    'data format:
  5.    '[http://example.com/images/example.jpg]
  6.    'Result:
  7.    '<img src="http://example.com/images/example.jpg">
  8.    'Select text & run macros
  9.    
  10.     Dim IMGTemplate As String
  11.     Dim IMGAddr As String
  12.     Dim IMGOut As String
  13.     Dim IMGStart As Integer
  14.     Dim IMGEnd As Integer
  15.    
  16.     IMGTemplate = "<img src=""%addr%"">"
  17.     IMGStart = InStr(1, Selection.Text, "[")
  18.     IMGEnd = InStr(1, Selection.Text, "]")
  19.     If (IMGStart = 0) Or (IMGEnd = 0) Then
  20.         MsgBox "No Link :("
  21.         Exit Sub
  22.     End If
  23.    
  24.     IMGAddr = Trim$(Mid$(Selection.Text, IMGStart + 1, IMGEnd - IMGStart - 1))
  25.     IMGOut = Replace(IMGTemplate, "%addr%", IMGAddr)
  26.    
  27.     Selection.Text = IMGOut
  28.     Selection.MoveRight Unit:=wdCharacter, Count:=1
  29.  
  30. End Sub
RAW Paste Data
Top