#1
|
|||
|
|||
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 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. |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Issue of 2 fixed bullet points indent setting work together (code included) | puff | Word VBA | 5 | 12-17-2017 05:52 PM |
image appering as code | TedW | Excel | 1 | 11-17-2015 10:11 PM |
insert Image ?? | Jazz | Outlook | 1 | 09-10-2015 04:34 AM |
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 |