PDA

View Full Version : Setting up a button activated insert image vba



alexg7828
08-03-2017, 12:06 PM
Hi,

I am looking to find a way to create a button or link in Microsoft Word that when selected will open the insert image function and navigate to a folder in a directory depending on parts of text on the document for example if the document is called MAG12 and the button is in the section called Precontract the vba would select insert image then open folder MAG12 then folder Precontract and let me manually select the image I want to insert.

Basically I am trying to reduce from 7 clicks and folder navigating to 1 with a manual image selection. If that makes sense

any help or point to resources would be great, I'm just starting out with VBA

cheers Alex

NoNameNeeded
08-03-2017, 12:43 PM
I won't be able to solve your problem, but there is a macro which always shows the directory the doc file is in.
So, let's say your doc file is in c:\x\y\mypictures\mygreatpictures and you want to insert a picture the dialog box will open in that exact directory and you don't have to navigate to this directory.

But unfortunately it's not a normal macro but you need to create a module named "AutoExec" with this code

Option Explicit

Private objImagePath As clsImagePath

Public Sub AutoExec()
Set objImagePath = New clsImagePath
Set objImagePath.obj = Word.Application
End Sub


...and another class module containing this code:

Option Explicit

Public WithEvents obj As Word.Application

Private Sub obj_DocumentChange()
If Word.Documents.Count > 0 Then
Options.DefaultFilePath(Path:=wdPicturesPath) = ActiveDocument.Path
End If
End Sub


And the class module needs to have the name clsImagePath

P.S: Creating a button which invokes the insert image dialog box should be easy. You can accomplish this by recording a macro and assigning a button to this macro.

macropod
08-03-2017, 11:38 PM
If you insert a picture content control into your document at the appropriate point, merely clicking on it's icon will trigger the display of the InsertPicture dialogue.