Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-23-2019, 01:50 AM
Ab1974 Ab1974 is offline Button Windows 10 Button Office 2010
Novice
Button
 
Join Date: Jun 2019
Posts: 3
Ab1974 is on a distinguished road
Default Button


How do i use a button to user insert a picture with specific height and with, specific place in the document and behind other pictures?
Reply With Quote
  #2  
Old 06-23-2019, 06:11 AM
gmayor's Avatar
gmayor gmayor is offline Button Windows 10 Button Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
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 of
Default

The code would be essentially that at https://www.msofficeforums.com/word/...-document.html with the addition of

Code:
While .ZOrderPosition > 1
    .ZOrder msoSendBackward
Wend
before the second End With
__________________
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 06-24-2019, 01:15 AM
Ab1974 Ab1974 is offline Button Windows 10 Button Office 2010
Novice
Button
 
Join Date: Jun 2019
Posts: 3
Ab1974 is on a distinguished road
Default

thanks but how do i let de user search for a picture?

instead of a specific picture
Dim oShp As Shape
Set oShp = ActiveDocument.Shapes.AddPicture(FileName:="C:\Path\ImageName.jpg", _
SaveWithDocument:=True)
Reply With Quote
  #4  
Old 06-24-2019, 01:38 AM
gmayor's Avatar
gmayor gmayor is offline Button Windows 10 Button Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
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 of
Default

Put the following function in the same module
Code:
Private Function BrowseForFile(Optional strTitle As String) As String
Dim fDialog As FileDialog
    On Error GoTo err_Handler
    Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
    With fDialog
        .TITLE = strTitle
        .AllowMultiSelect = False
        .Filters.Clear
        .Filters.Add "Graphics Files", "*.jpg,*.png,*.bmp"
        .InitialView = msoFileDialogViewList
        If .Show <> -1 Then GoTo err_Handler:
        BrowseForFile = fDialog.SelectedItems.Item(1)
    End With
lbl_Exit:
    Exit Function
err_Handler:
    BrowseForFile = vbNullString
    Resume lbl_Exit
End Function
and change the code text you quoted to
Code:
Dim oShp As Shape
Dim strFName As String
strFName = BrowseForFile("Select the picture to insert")
Set oShp = ActiveDocument.Shapes.AddPicture(FileName:=strFName, _
SaveWithDocument:=True)
__________________
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
  #5  
Old 06-25-2019, 05:12 AM
Ab1974 Ab1974 is offline Button Windows 10 Button Office 2010
Novice
Button
 
Join Date: Jun 2019
Posts: 3
Ab1974 is on a distinguished road
Default

While .ZOrderPosition > 1
.ZOrder msoSendBackward
Wend

doesnt work. word crashes...

this is what i've done.

With oShp
With .WrapFormat
.Type = wdWrapSquare
.Side = wdWrapBoth
.DistanceTop = InchesToPoints(0.1)
.DistanceBottom = InchesToPoints(0.1)
.DistanceLeft = InchesToPoints(0.1)
.DistanceRight = InchesToPoints(0.1)
End With
.LockAspectRatio = msoTrue
.Width = InchesToPoints(9)
.Height = InchesToPoints(4) ' The displayed width of the picture
.Left = InchesToPoints(0.1) - ActiveDocument.PageSetup.LeftMargin 'The distance from the left edge of the paper
.Top = InchesToPoints(2) - ActiveDocument.PageSetup.TopMargin 'The distance from the top edge of the paper
While .ZOrderPosition > 1
.ZOrder msoSendBackward
Wend
End With


lbl_Exit:
Set oShp = Nothing
Exit Sub
Reply With Quote
  #6  
Old 06-25-2019, 06:07 AM
gmayor's Avatar
gmayor gmayor is offline Button Windows 10 Button Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
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 of
Default

You have a conflict between the use of height and width and lock aspect. You only need the width The following works in Word 2010 and later.

Code:
Option Explicit

Sub InsertImage()
Dim oShp As Shape
Dim strFName As String
    strFName = BrowseForFile("Select the picture to insert")
    Set oShp = ActiveDocument.Shapes.AddPicture(FileName:=strFName, _
                                                SaveWithDocument:=True)
    With oShp
        With .WrapFormat
            .Type = wdWrapSquare
            .Side = wdWrapBoth
            .DistanceTop = InchesToPoints(0.1)
            .DistanceBottom = InchesToPoints(0.1)
            .DistanceLeft = InchesToPoints(0.1)
            .DistanceRight = InchesToPoints(0.1)
        End With
        .LockAspectRatio = msoTrue
        .Width = InchesToPoints(9)    ' The displayed width of the picture
        .Left = InchesToPoints(0.1) - ActiveDocument.PageSetup.LeftMargin    'The distance from the left edge of the paper
        .Top = InchesToPoints(2) - ActiveDocument.PageSetup.TopMargin    'The distance from the top edge of the paper
        While .ZOrderPosition > 1
            .ZOrder msoSendBackward
        Wend
    End With
lbl_Exit:
    Set oShp = Nothing
    Exit Sub
End Sub

Private Function BrowseForFile(Optional strTitle As String) As String
Dim fDialog As FileDialog
    On Error GoTo err_Handler
    Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
    With fDialog
        .Title = strTitle
        .AllowMultiSelect = False
        .Filters.Clear
        .Filters.Add "Graphics Files", "*.jpg,*.png,*.bmp"
        .InitialView = msoFileDialogViewList
        If .Show <> -1 Then GoTo err_Handler:
        BrowseForFile = fDialog.SelectedItems.Item(1)
    End With
lbl_Exit:
    Exit Function
err_Handler:
    BrowseForFile = vbNullString
    Resume lbl_Exit
End Function
__________________
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
How to create a "Font color" button and a "Highlight text" button in the Quick Launch toolbar ? gloub Word 12 02-19-2019 03:19 PM
Help with a Command Button dkohnken Word VBA 5 03-18-2015 10:13 PM
Button Option Button help ksigcajun Word VBA 1 01-15-2015 01:36 PM
Button How to run two button macros with one button? Geza59 Excel Programming 1 02-14-2013 12:11 AM
Macro Button B2W Excel 2 06-18-2010 09:36 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:08 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