+ Reply to Thread
Results 1 to 4 of 4

Userform to edit macro?

Hybrid View

  1. #1
    Registered User
    Join Date
    05-20-2010
    Location
    London, England
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    33

    Userform to edit macro?

    Hi,

    I had a little search but couldn't find anything on the subject.
    I'm wondering if its possible to create a userform that can update code in a macro?

    Specifically, I have a macro that updates external data but the link for this external data changes weekly. So rather than have to edit the macro manually, the userform will do it when requested.

    Here is an example of the code, with the sections required to be changed highlighted in red:

    ActiveWorkbook.UpdateLink Name:="T:\Filepath\Data\week 36\file wk36.xlsx", Type:= _
    xlExcelLinks

    Thanks in advance for any time or assistance with this.

  2. #2
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: Userform to edit macro?

    hi mungel
    with your userform

    ActiveWorkbook.UpdateLink Name:="T:\Filepath\Data\week " & Texbox1.value & "\file wk" & Texbox1.value & ".xlsx", Type:= _
    xlExcelLinks
    where textbox1 has the 36 text
    If the solution helped please donate to RSPCA

    Site worth visiting: Rabbitohs

  3. #3
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Userform to edit macro?

    You could add a Browse for file button or simply ask the user within the code to select a file

    Option Explicit
    
    Sub openfile()
        Dim sFil As String
        Dim sTitle As String
        Dim sWb As String
        Dim iFilterIndex As Integer
    
        On Error GoTo err_handler
        ' Set up list of file filters
        sFil = "Excel Files (*.xls),*.xls"
        ' Display *.xls by default
        iFilterIndex = 1
        ' Set the dialog box caption
        sTitle = "Select  File to Open"
        ' Get the filename
        sWb = Application.GetOpenFilename(sFil, iFilterIndex, sTitle)
    
        Workbooks.Open Filename:=sWb
        'rest of code here
        Exit Sub
    err_handler:
        MsgBox "No selection made", vbCritical, "Cancelled"
    End Sub
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  4. #4
    Registered User
    Join Date
    05-20-2010
    Location
    London, England
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    33

    Re: Userform to edit macro?

    Hi,

    Thanks for the replies.
    Both are excellent ideas and I will try them both out to see which fits better.
    The general idea is to make the weekly update process easy enough for anyone to do.
    Unfortunately, that means 'really' computer illiterate people in some cases.

    Many thanks.


+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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