Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-03-2017, 10:41 PM
Guessed's Avatar
Guessed Guessed is offline Word 2016 command name Windows 10 Word 2016 command name Office 2013
Expert
Word 2016 command name
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,176
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default Word 2016 command name

I'm having trouble with an old macro that fails in Word 2016 and can't seem to find the new command name for this code.


CommandBars.ExecuteMso ("PictureChange")

This is the command that you see when you right click an image in Word and choose Change Picture > From a File

I'm using this line of code as part of a larger macro that allows the user to replace a graphic and crop the replacement to the same dimensions.

Does anyone know an alternate way to achieve this in Word 2016 when the inline shape is of type wdInlineShapePicture?
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #2  
Old 07-04-2017, 03:41 AM
gmayor's Avatar
gmayor gmayor is offline Word 2016 command name Windows 10 Word 2016 command name Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,142
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

The following will replace a selected inline image with the named image and set the image width to the same size as the original, which for similar aspect ratio pictures means the same size:

Code:
Dim oRng As Range
Dim oShp As InlineShape
Dim lngWidth As Long
    Set oRng = Selection.InlineShapes(1).Range
    lngWidth = Selection.InlineShapes(1).Width
    oRng.Text = ""
    Set oShp = oRng.InlineShapes.AddPicture("C:\Path\Filename.jpg")
    oShp.LockAspectRatio = msoTrue
    oShp.Width = lngWidth
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 07-04-2017, 05:22 AM
Guessed's Avatar
Guessed Guessed is offline Word 2016 command name Windows 10 Word 2016 command name Office 2013
Expert
Word 2016 command name
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,176
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Thanks Graham but I need to include a prompt to allow the user to choose an image to do the replacement with. It was all so easy with that line previously with Word 2007, 2010, 2013 and some versions of 2016 but it seems to fall over on a few 2016 machines now and I can't work out why it doesn't work anymore. The Office2016FluentUserInterfaceControlIdentifiers downloaded from MS lists PictureChange as a command but apparently it doesn't work in all versions of Word 2016

The rest of the code works fine and crops the replacement image if the aspect ratio doesn't match the graphic it is replacing.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #4  
Old 07-04-2017, 09:06 PM
gmayor's Avatar
gmayor gmayor is offline Word 2016 command name Windows 10 Word 2016 command name Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,142
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

I have no idea why the code you have used previously no longer works for you (it doesn't work here), but adding file selector is easy enough
Code:
Dim oRng As Range
Dim oShp As InlineShape
Dim sName As String
Dim lngWidth As Long
Dim fDialog As FileDialog
    Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
    With fDialog
        .Title = "Select the image to insert"
        .InitialFileName = Environ("USERPROFILE") & Chr(92) & "Pictures"
        .AllowMultiSelect = False
        .Filters.Clear
        .Filters.Add "Graphics Files", "*.jpg,*.png,*.gif, *.bmp, *.tif"
        .InitialView = msoFileDialogViewList
        If Not .Show = -1 Then Exit Sub
        sName = fDialog.SelectedItems.Item(1)
    End With
    Set oRng = Selection.InlineShapes(1).Range
    lngWidth = Selection.InlineShapes(1).Width
    oRng.Text = ""
    Set oShp = oRng.InlineShapes.AddPicture(sName)
    oShp.LockAspectRatio = msoTrue
    oShp.Width = lngWidth
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Word 2016 command name Visio 2016 diagrams embeded in word 2016 not drawing properly stubbo66 Visio 2 08-24-2016 05:58 PM
Word 2016 command name Using a display alert command in Word ch1325 Word VBA 2 04-30-2016 06:50 AM
Word 2016 command name How to run command in word si14 Word 3 06-10-2015 04:08 PM
From the command line, how do I run a Word macro? jdockstader Word 7 02-04-2013 06:09 AM
Invoking a command line from inside Word bolpom Word 1 03-16-2011 03:03 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:43 PM.


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