Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 01-13-2018, 05:47 PM
puff puff is offline VBA to insert an image and centralize it (code included) Windows 7 64bit VBA to insert an image and centralize it (code included) Office 2013
Advanced Beginner
VBA to insert an image and centralize it (code included)
 
Join Date: Apr 2017
Posts: 60
puff is on a distinguished road
Question VBA to insert an image and centralize it (code included)

Hi all. My target is fairly simple and it's just like use alt+I to open the insert image dialog, choose an image to insert and then centralize the image. My code so far:

Code:
Sub InsertPic()
    Dim oDialog As Dialog
    Dim strFile As String
    Dim oImage As Object
        Set oDialog = Dialogs(wdDialogInsertPicture)
        With oDialog
            .Display
            If .Name <> "" Then
                strFile = .Name
            End If
        End With
        
        Set oImage = Selection.InlineShapes.AddPicture(strFile)
        With oImage
            .LockAspectRatio = msoTrue
            .Height = 0.5 * .Height
            .Width = 0.5 * .Width 
            Set oRng = .ConvertToShape
        End With
        
        With oRng
            oRng.Select
            Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
        End With
    Set oDialog = Nothing
    Set oImage = Nothing
    Set oRng = Nothing
End Sub
Questions:
1. The image inserted by my code has that blue anchor on the upper left corner and the centralizing part doesn't work. How can I get rid of that and make the image embedded in the texts to centralize the image? I think I messed up the difference between inline shape and shape objects.



2. Is that possible for me to set a default file location when the insert image dialog is open? For example, C:\Users\atom\Desktop\PDF

3. My code also includes a part where I want to resize the picture to 50% after insertion, but the resulting image is super small. Did I make a mistake there?

4. What changes do I need to make if I want to insert all the images from a file and process them as described above?

Thank you very much for your consideration. Any improvement of the original code is also welcomed.
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA to insert an image and centralize it (code included) Issue of 2 fixed bullet points indent setting work together (code included) puff Word VBA 5 12-17-2017 05:52 PM
VBA to insert an image and centralize it (code included) image appering as code TedW Excel 1 11-17-2015 10:11 PM
VBA to insert an image and centralize it (code included) insert Image ?? Jazz Outlook 1 09-10-2015 04:34 AM
VBA to insert an image and centralize it (code included) Insert am Image phamh PowerPoint 1 02-25-2015 04:40 AM
Background image vs. insert image lilaria PowerPoint 0 04-18-2011 08:45 AM

Other Forums: Access Forums

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