Results 1 to 4 of 4

Need To open and Save a folder location selected by user

Threaded View

  1. #1
    Registered User
    Join Date
    04-14-2014
    Location
    Three Forks, MT
    MS-Off Ver
    Excel 2007
    Posts
    3

    Need To open and Save a folder location selected by user

    I have the below code set that I need help modifying. What I am trying to do:

    1) Have the hard coded folder path be chosen by a user and then saved so that it can be used later in the code (Sub Rename Files)
    2) Have that folder path be the selected location for Sub Rename Files so that the user does not have to reselect the folder that they chose originally (step 1)

    Please let me know if there are any questions.
    Public Sub AddOlEObject()
    
     Dim mainWorkBook As Workbook
     
        Set mainWorkBook = ActiveWorkbook
        Sheets("Sheet1").Activate
        FolderPath = "C:\"
        Set fso = CreateObject("Scripting.FileSystemObject")
        NoOfFiles = fso.GetFolder(Folderpath).Files.Count
        Set listfiles = fso.GetFolder(Folderpath).Files
        For Each fls In listfiles
           strCompFilePath = Folderpath & "\" & Trim(fls.Name)
            If strCompFilePath <> "" Then
                If (InStr(1, strCompFilePath, "jpg", vbTextCompare) > 1 _
                Or InStr(1, strCompFilePath, "jpeg", vbTextCompare) > 1 _
                Or InStr(1, strCompFilePath, "tif", vbTextCompare) > 1 _
                Or InStr(1, strCompFilePath, "png", vbTextCompare) > 1) Then
                     counter = counter + 1
                      Sheets("Sheet1").Range("A" & counter + 1).Value = fls.Name
                      Sheets("Sheet1").Range("B" & counter + 1).ColumnWidth = 110
                    Sheets("Sheet1").Range("B" & counter + 1).RowHeight = 150
                    Sheets("Sheet1").Range("B" & counter + 1).Activate
                    Call insert(strCompFilePath, counter)
                    Sheets("Sheet1").Activate
                End If
            End If
        Next
    End Sub
    
    
    
    Function insert(PicPath, counter)
    'MsgBox PicPath
        With ActiveSheet.Pictures.insert(PicPath)
            With .ShapeRange
                .LockAspectRatio = msoTrue
                .Width = 100
                .Height = 130
            End With
            .Left = ActiveSheet.Range("B" & counter + 1).Left
            .Top = ActiveSheet.Range("B" & counter + 1).Top
            .Placement = 1
            .PrintObject = True
        End With
    End Function
    
    Sub RenameFiles()
    'Updateby20141124
    Dim xDir As String
    Dim xFile As String
    Dim xRow As Long
    With Application.FileDialog(msoFileDialogFolderPicker)
        .AllowMultiSelect = False
    If .Show = -1 Then
        xDir = .SelectedItems(1)
        xFile = Dir(xDir & Application.PathSeparator & "*")
        Do Until xFile = ""
            xRow = 0
            On Error Resume Next
            xRow = Application.Match(xFile, Range("A:A"), 0)
            If xRow > 0 Then
                Name xDir & Application.PathSeparator & xFile As _
                xDir & Application.PathSeparator & Cells(xRow, "H").Value
            End If
            xFile = Dir
        Loop
    End If
    End With
    End Sub
    Moderator's note: Please take the time to review our rules. There aren't many, and they are all important. Rule #3 requires code tags. I have added them for you this time because you are a new member. --6StringJazzer
    Last edited by 6StringJazzer; 07-28-2016 at 10:53 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Open Folder (Prompt User for final folder name in location path)
    By synergeticink in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-21-2014, 03:33 PM
  2. [SOLVED] [Help]macro to open file browser, to select a location, and save the location to a cell
    By zhuleijia in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-06-2013, 09:56 AM
  3. [SOLVED] Macro to prompt user for folder location and save acitve workbook.
    By maacmaac in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-06-2013, 06:20 PM
  4. Replies: 1
    Last Post: 07-24-2012, 09:53 AM
  5. User input for folder location
    By jmckee in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-02-2010, 03:09 PM
  6. Open a folder location with VBA?
    By comptechbranden in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-10-2007, 10:59 AM
  7. [SOLVED] Open folder - Activeworkbook location
    By al007 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-26-2006, 09:40 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1