Consulting

Results 1 to 3 of 3

Thread: Setting up a button activated insert image vba

  1. #1

    Setting up a button activated insert image vba

    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

  2. #2
    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.

  3. #3
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    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.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •