+ Reply to Thread
Results 1 to 2 of 2

user friendly box

Hybrid View

  1. #1
    Registered User
    Join Date
    01-18-2014
    Location
    canada
    MS-Off Ver
    Excel 2003
    Posts
    39

    user friendly box

    I need ideas

    example : i want to sum different work books but instead of writing a formula every time, i want a box that i can input the files and it will write the formula automatically

  2. #2
    Forum Contributor
    Join Date
    12-14-2013
    Location
    Tilburg, Nederland
    MS-Off Ver
    Excel 2010
    Posts
    256

    Re: user friendly box

    It is possible.
    Try something like the code below.
    Sub AddFormula2SelectedWb()
        '   Macro   :   Excample for adding formale to selected files
        '   Authur  :   Gerard Veldstra
        '
        '   Date    :   27 jan 2014
        '   For     :   ExcelForum.com
        '
        Dim sSDrive As String
        Dim sPath As String
        Dim sFName As String
        Dim iCount As Integer
        Dim fd As FileDialog
        Dim vrtSelectedItem As Variant
        Dim wb As Workbook
        
        ' Save the current directory.
        sSDrive = CurDir
    
        ' Set the path to the folder that you want to open.
        sPath = "H:\001ExcelForum\2014\jan\Multi books"
    
        ' Change drive/directory to sPath.
        ChDrive sPath
        ChDir sPath
        Set fd = Application.FileDialog(msoFileDialogFilePicker)
        With fd
        
            .AllowMultiSelect = True
            .Title = "Choose workbook for formula adding"
            .InitialFileName = sPath
            .InitialView = msoFileDialogViewList
        'show Excel workbooks and macro workbooks
            .Filters.Clear
            .Filters.Add "Excel workbooks", "*.xlsx*"
            .Filters.Add "Excel macros", "*.xlsm"
            .Filters.Add "Excel 97-2003 Files", "*.xls"
            .FilterIndex = 2
            .ButtonName = "Ad formula"
            If .Show = -1 Then
                'Step through each string in the FileDialogSelectedItems collection.
                iCount = 0
                Application.ScreenUpdating = False
                Application.EnableEvents = False
                For Each vrtSelectedItem In .SelectedItems
                    sFName = Right(vrtSelectedItem, Len(vrtSelectedItem) - InStrRev(vrtSelectedItem, Application.PathSeparator, , 1))
                    On Error Resume Next
                        Set wb = Workbooks.Open(vrtSelectedItem)
                        On Error GoTo 0
                        If Not wb Is Nothing Then
                            ' Add the formula to sheet
                            Workbooks(sFName).Sheets(1).Range("A1").Formula = "=5+6" 'Change formula to desire
                            wb.Close SaveChanges:=True
                        End If
                Next
                Application.ScreenUpdating = True
                Application.EnableEvents = True
            End If
        End With
    
        Set fd = Nothing
        ChDrive sSDrive
        ChDir sSDrive
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] User-friendly editing
    By menim in forum Excel General
    Replies: 5
    Last Post: 01-01-2014, 06:53 PM
  2. flookup macro user-friendly
    By wallov in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-30-2013, 05:29 AM
  3. Making a spreadsheet user friendly
    By quiggdavid in forum Excel General
    Replies: 10
    Last Post: 03-30-2011, 07:18 PM
  4. User friendly summarising
    By murphybrendan in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-12-2010, 06:54 AM
  5. More cosmetically pleasing & user friendly
    By warby23 in forum Excel General
    Replies: 1
    Last Post: 02-09-2009, 04:54 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