Results 1 to 3 of 3
  1. #1
    2 Star Lounger
    Join Date
    Apr 2002
    Location
    East Tennessee
    Posts
    179
    Thanks
    3
    Thanked 0 Times in 0 Posts

    A macro to take me to a folder and allow me then to make a selection

    I have a group of screen shots in a folder.
    I was trying to record a macro to take me to the folder but then allow me to make a selection.

    If I actually do select a file it works fine, but will always insert the same file. I want use "Insert>Picture>from file'.

    This the macro that was generated with a file selected.
    Sub Macro3()
    '
    ' Macro3 Macro
    '
    Selection.InlineShapes.AddPicture FileName:= _
    "C:\Documents and Settings\Harold\My Documents\PrintScreen Files\CableCast030.jpg" _
    , LinkToFile:=False, SaveWithDocument:=True
    End Sub

    Thanks in advance!
    Win 8, Firefox 16.0.2, Thunderbird 15.0.2

  2. #2
    3 Star Lounger
    Join Date
    Feb 2001
    Location
    Willow Grove, Pennsylvania, USA
    Posts
    205
    Thanks
    4
    Thanked 49 Times in 40 Posts
    You can't record this macro, because the recorder will always capture the full name of whatever file you choose in the dialog during the recording session, and that's the only file the macro will ever know about. Instead the following macro sets the default Pictures path, calls up the dialog, inserts whatever file you choose, and then puts the Pictures path back to its original value.

    Code:
    Sub InsertPictureSpecialFolder()
        Dim fldr As String
        Dim oldFldr As String
        Dim picfile As String
        Dim dlg As Dialog
        Dim rtn As Long
        
        On Error GoTo finish  ' if it errors, make sure the old path is reset
        
        ' replace the Pictures path with the desired folder path,
        ' saving the old value for later
        fldr = "C:\Documents and Settings\Harold\My Documents\PrintScreen Files\"
        oldFldr = Options.DefaultFilePath(wdPicturesPath)
        Options.DefaultFilePath(wdPicturesPath) = fldr
        
        ' display the Insert Picture dialog and store the selected file name
        Set dlg = Dialogs(wdDialogInsertPicture)
        With dlg
            rtn = .Display
            picfile = .Name
        End With
        
        ' the return value is -1 if the OK button was clicked
        If rtn = -1 Then
            Selection.InlineShapes.AddPicture FileName:=picfile, _
                linktofile:=False, savewithdocument:=True
        End If
        
    finish:
        ' restore the old value of the Picture path
        Options.DefaultFilePath(wdPicturesPath) = oldFldr
    End Sub

  3. The Following User Says Thank You to jjfreedman For This Useful Post:

    halek2 (2012-05-24)

  4. #3
    2 Star Lounger
    Join Date
    Apr 2002
    Location
    East Tennessee
    Posts
    179
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Thanks for the reply, I'll give it a go!
    Win 8, Firefox 16.0.2, Thunderbird 15.0.2

Tags for this Thread

Posting Permissions

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