Adding a image into word (using vbscript)


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 7 of 7

Thread: Adding a image into word (using vbscript)

  1. #1
    Join Date
    Sep 2008
    Posts
    4

    Adding a image into word (using vbscript)

    Hallo,

    I need to replace a textstring with a image file (.jpg) in MS Word using vbscript.

    I can already open word and search for the textstring.

    I can also replace it already with another textstring - but I NEED to replace it with an IMAGE - file !!

    Hereīs my code:
    Code:
    Dim oWord
    Err = 0
    On Error Resume Next
    'Set oWord = GetObject(, "Word.Application")
    
    Set oWord = CreateObject("Word.Application")
    oWord.Visible = TRUE
    oWord.Documents.Open("C:\WORD\MyWord.doc")
    
    Set objSelection = oWord.Selection
    
    oWord.Application.ScreenUpdating = False
    'oWord.ActiveWindow.ActivePane.View.ShowAll = True
    
    oWord.Selection.Find.Text = "STRING_TO_FIND"
    oWord.Selection.Find.Forward = True
    oWord.Selection.Find.Wrap = wdFindContinue
    oWord.Selection.Find.Format = False
    oWord.Selection.Find.MatchCase = False
    oWord.Selection.Find.MatchWholeWord = False
    oWord.Selection.Find.MatchWildcards = False
    oWord.Selection.Find.MatchSoundsLike = False
    oWord.Selection.Find.MatchAllWordForms = False
    
    while oWord.Selection.Find.Execute = True
    
    '------------- ! ! ! -----------------------------
    'REPLACEīs THE Text with the string "TEXT":
    'objSelection.TypeText "TEXT"
    
    'PS: That is working - but I need to insert a image 
    'instead of the text - string 
    '-----------------------------------------------
    
    
    '--------------- THIS IS NOT WORKING !!! :( 
    oWord.Selection.InlineShapes.AddPicture FileName:="C:\IMAGE\myimage.TIF", LinkToFile:=False, SaveWithDocument:=True	
    	
    '--------------- HOW CAN I IMPORT THE IMAGE ???----- 	
    
    	
    Wend
    
    oWord.Application.ScreenUpdating = True
    'oWord.ActiveWindow.ActivePane.View.ShowAll = False
    
    oWord.Documents(1).Protect wdAllowOnlyFormFields, True
    
    'oWord.ActiveDocument.Save
    THANK YOU!

  2. #2
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    Welcome to DevX

    What error are you getting?
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  3. #3
    Join Date
    Sep 2008
    Posts
    4

    Unhappy

    Hallo!

    I simply cannot find a vbscript code that addīs a image into MS Word.

    Itīs working with VBA Makro - but the VBA Code is not working in
    vbscript

    VBA-Code:

    --------------- THIS IS NOT WORKING IN VBScript!!!
    oWord.Selection.InlineShapes.AddPicture FileName:="C:\IMAGE\myimage.TIF", LinkToFile:=False, SaveWithDocument:=True


    'End of Code
    If I run it I receive Error Code 800A0400 (Expected statement [Missing Caracter])

    ???

    Thx,
    Mage

  4. #4
    Join Date
    Sep 2008
    Posts
    4
    OK,

    I found out that VBScript does not accept := (only =)

    Now I receive an other error: 800A1420 (invalid Path)

    But the path is correct: C:\MAKRO\Bild_004.TIF

  5. #5
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    Then maybe it is referring to a different path.
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  6. #6
    Join Date
    Sep 2008
    Posts
    4

    Smile Solution found

    Hallo!

    I have found the solution:
    Code:
    '-------------CODE-----------------------------
    
    Set objWord = CreateObject("Word.Application")
    objWord.Visible = True
    Set objDoc = objWord.Documents.Add()
    Set objSelection = objWord.Selection
    
    Set objShape = objDoc.Shapes
    objShape.AddPicture("C:\Scripts\Logo.jpg")
    
    '----------END-OF-CODE-----------------------
    Thx anyway!
    You can close this Thread.
    Last edited by Hack; 09-26-2008 at 07:16 AM. Reason: Added Code Tags

  7. #7
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    Thank you for coming back and posting your solution.

    Hopefully it will help someone else with the same, or similiar, question.

    (PS: For clarity sake, I edited your post and added [code]your code goes here[/code] tags.)
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

Similar Threads

  1. Replies: 3
    Last Post: 03-19-2008, 02:10 AM
  2. Adding Ms word functionality to the Windows form
    By software_develo in forum .NET
    Replies: 0
    Last Post: 12-01-2005, 08:43 AM
  3. VBscript adding hyperlink to excel
    By mattlucas in forum VB Classic
    Replies: 1
    Last Post: 11-22-2005, 02:09 AM
  4. Script for scrolling
    By Mark in forum Web
    Replies: 3
    Last Post: 08-30-2001, 11:45 AM
  5. Replies: 0
    Last Post: 03-08-2001, 02:12 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center