Microsoft Office Forums

Go Back   Microsoft Office Forums > Microsoft Word > Word VBA

Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 03-20-2017, 05:31 AM
stewarto stewarto is offline Windows 10 Office 2016
Novice
 
Join Date: Mar 2017
Location: Haarlem, Netherlands
Posts: 4
stewarto is on a distinguished road
Question inserting an image at current position

I have a macro which inserts an image at the current position but since a short while it inserts at the top of the page!



Can anyone help?

myperson = "john_doe"
myfile = "g:\office\files\" + myperson + ".bmp"
ActiveDocument.Shapes.AddPicture(Anchor:=Selection .Range, FileName:=myfile, _
LinkToFile:=False, SaveWithDocument:=True).WrapFormat.Type = wdWrapSquare
Reply With Quote
  #2  
Old 03-20-2017, 07:16 AM
dwirony dwirony is offline Windows 7 64bit Office 2003
Advanced Beginner
 
Join Date: Oct 2016
Posts: 48
dwirony is on a distinguished road
Default

Try this instead:

Code:
Sub InsertPicture()
myperson = "john_doe"
myfile = "g:\office\files\" + myperson + ".bmp"
Selection.InlineShapes.AddPicture FileName:= _
        myfile, LinkToFile:=False, _
        SaveWithDocument:=True

End Sub
Although this may lose your wrap format. Is that something you need?
Reply With Quote
  #3  
Old 03-20-2017, 07:39 AM
stewarto stewarto is offline Windows 10 Office 2016
Novice
 
Join Date: Mar 2017
Location: Haarlem, Netherlands
Posts: 4
stewarto is on a distinguished road
Default

Thanks for your help, dwirony, but I get the following error (translated from the original Dutch)

error -2147467259 (80004005)
Method AddPicture of object InlineShapes failed
Reply With Quote
  #4  
Old 03-20-2017, 07:53 AM
dwirony dwirony is offline Windows 7 64bit Office 2003
Advanced Beginner
 
Join Date: Oct 2016
Posts: 48
dwirony is on a distinguished road
Default

Strange - It's working fine on my computer. Are you sure you have the right filepath?
Reply With Quote
  #5  
Old 03-20-2017, 08:02 AM
stewarto stewarto is offline Windows 10 Office 2016
Novice
 
Join Date: Mar 2017
Location: Haarlem, Netherlands
Posts: 4
stewarto is on a distinguished road
Default

Yes. The filepath works with my macro, but it puts the image at the top of the page
Reply With Quote
  #6  
Old 03-20-2017, 09:29 AM
dwirony dwirony is offline Windows 7 64bit Office 2003
Advanced Beginner
 
Join Date: Oct 2016
Posts: 48
dwirony is on a distinguished road
Default

So it was working fine before but now it is not? Is it because there is a space between "Selection" and ".Range"?

Code:
Anchor:=Selection .Range
Can you try removing that space?
Reply With Quote
  #7  
Old 03-21-2017, 02:40 AM
stewarto stewarto is offline Windows 10 Office 2016
Novice
 
Join Date: Mar 2017
Location: Haarlem, Netherlands
Posts: 4
stewarto is on a distinguished road
Default

Sorry, it was FFS (fat finger syndrome).

The space does not exist in the real macro.
Reply With Quote
  #8  
Old 03-21-2017, 02:37 PM
dwirony dwirony is offline Windows 7 64bit Office 2003
Advanced Beginner
 
Join Date: Oct 2016
Posts: 48
dwirony is on a distinguished road
Default

I'm afraid that with my limited knowledge I cannot help you...

Hopefully someone like gmaxey or macropod will come along and solve your mystery
Reply With Quote
Reply

Tags
word vba
Please reply to this thread with any new information or opinions.

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to position an image at a specific location from the edge of the screen / paper? SpeedD PowerPoint 1 01-28-2015 08:04 AM
Losing image resolution when inserting image into MS word (2011: Mac) Mario.N Drawing and Graphics 0 11-23-2014 02:38 AM
Problem Inserting Image rbonnell PowerPoint 1 07-22-2014 07:15 AM
Word 2010 how do i set default position for image sam2149 Word 2 03-29-2014 01:41 AM
Macro for moving one cell down from current position Johnny thunder Word 3 04-07-2011 04:44 PM


All times are GMT -7. The time now is 02:32 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
MSOfficeForums.com is not affiliated with Microsoft