Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-13-2017, 12:11 PM
Fritesmodern Fritesmodern is offline Inserting pictures in a word document launched from another application Windows 7 32bit Inserting pictures in a word document launched from another application Office 2016
Novice
Inserting pictures in a word document launched from another application
 
Join Date: Nov 2017
Posts: 1
Fritesmodern is on a distinguished road
Default Inserting pictures in a word document launched from another application

I am trying to create a word document from MS Access which inserts a picture into it. The below code triggers an error at the the last statement. Can anybody tell me what is going on?





Thanks





Dim wdApp As Word.Application
Dim As Word.Document

Dim shp As Shape



Set wdApp = CreateObject("Word.APPLICATION")
wdApp.Visible = True
Set wdDoc = wdApp.Documents.Add


Set shp = wdDoc.ActiveWindow.Selection.InlineShapes.AddPictu re(FileName:="C:\MyPicture.jpg", LinkToFile:=False, SaveWithDocument:=True).ConvertToShape
Reply With Quote
  #2  
Old 11-13-2017, 02:01 PM
macropod's Avatar
macropod macropod is offline Inserting pictures in a word document launched from another application Windows 7 64bit Inserting pictures in a word document launched from another application Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

1. Given that you're running a new Word session, you don't need CreateObject; you can use New instead.
2. You need to be specific as to which application your Shape belongs; otherwise it is assumed to belong to the calling app, not the called one.
3. You don't need ActiveWindow.Selection; instead you can tell Word precisely where the pic should go.

Try something along the lines of:
Code:
Dim wdApp As New Word.Application, wdDoc As Word.Document, wdShp As Word.Shape

wdApp.Visible = True
Set wdDoc = wdApp.Documents.Add
Set wdShp = wdDoc.InlineShapes.AddPicture(FileName:="C:\MyPicture.jpg", LinkToFile:=False, _
  SaveWithDocument:=True, Range:=wdDoc.Range.Characters.Last).ConvertToShape
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 11-13-2017, 02:21 PM
macropod's Avatar
macropod macropod is offline Inserting pictures in a word document launched from another application Windows 7 64bit Inserting pictures in a word document launched from another application Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Cross-posted at: https://answers.microsoft.com/en-us/...3-dfed8f6aaecd
For cross-posting etiquette, please read: http://www.excelguru.ca/content.php?184
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Inserting pictures in a word document launched from another application Word Table inserting Pictures stu_c Word Tables 2 07-28-2022 02:39 PM
Inserting pictures in a word document launched from another application Office 365 application crash on inserting jpg MichaelBourne Office 5 03-14-2018 01:40 PM
Inserting pictures in a word document launched from another application Inserting 3 pictures in a row in Word didlinghill Word 3 05-22-2017 03:55 AM
Inserting pictures in a word document launched from another application how keep word document highlighted when switching focus to another application? dylansmith Word 4 05-08-2013 01:21 AM
Inserting pictures in a word document launched from another application Inserting scanned pictures into word files Rosie173 Drawing and Graphics 9 05-11-2011 02:51 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:41 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft