+ Reply to Thread
Results 1 to 3 of 3

Change filepath in macro based on textbox in form input

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    01-27-2015
    Location
    New hampshire
    MS-Off Ver
    excel 2013
    Posts
    143

    Change filepath in macro based on textbox in form input

    I have this maco and I want the number in red to change based on the textbox1 value in the partnumberform.
    how can I do this

    Sub textdata()
    '
    ' textdata Macro
         
        With ActiveSheet.QueryTables.Add(Connection:= _
            "TEXT;C:\Users\Joshua\Desktop\oasis\ 127196.txt", Destination:=Range("$A$1"))
              
            
            .Name = "127196_2"
            .FieldNames = True
            .RowNumbers = False
            .FillAdjacentFormulas = True
            .PreserveFormatting = True
            .RefreshOnFileOpen = False
            .RefreshStyle = xlInsertDeleteCells
            .SavePassword = False
            .SaveData = True
            .AdjustColumnWidth = True
            .RefreshPeriod = 0
            .TextFilePromptOnRefresh = False
            .TextFilePlatform = 437
            .TextFileStartRow = 1
            .TextFileParseType = xlDelimited
            .TextFileTextQualifier = xlTextQualifierDoubleQuote
            .TextFileConsecutiveDelimiter = False
            .TextFileTabDelimiter = True
            .TextFileSemicolonDelimiter = False
            .TextFileCommaDelimiter = False
            .TextFileSpaceDelimiter = False
            .TextFileOtherDelimiter = "|"
            .TextFileColumnDataTypes = Array(9, 1, 9, 9, 9, 9, 9, 9, 1)
            .TextFileTrailingMinusNumbers = True
            .Refresh BackgroundQuery:=False
        End With
        
        
        
        
    End Sub

  2. #2
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    365 Version 2409
    Posts
    2,789

    Re: Change filepath in macro based on textbox in form input

    Make a string variable.
    Dim strText as string

    strText = textbox1 value
    Then put it into the string like so.
    "TEXT;C:\Users\Joshua\Desktop\oasis\"& strText & ".txt",

    Edit: okay that's what I get for thinking, it's a string but it's still a variable so it has to be concatenated in or it just literally puts strText into the string, you do need the & "" stuff, so I changed it above to show it should be. I would reference the textbox1 as the formname.textbox1.value also.

    Good Luck!!!
    Last edited by skywriter; 02-27-2015 at 10:05 PM. Reason: Cause I messed up, that's why.

  3. #3
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,330

    Re: Change filepath in macro based on textbox in form input

    Hey Jenkins,

    Here is what I'd try first..

    Sub TextBox2Str()
        Dim PartStr As Double
        Dim FullPath As String
        PartStr = InputBox("What Part Number was that again?")
        FullPath = "TEXT;C:\Users\Joshua\Desktop\oasis\" & PartStr & ".txt"
        
        'With ActiveSheet.QueryTables.Add(Connection:= FullPath, Destination:=Range("$A$1"))
        
    End Sub
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

+ 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. i want to have a macro code change based on input from a textbox in a form
    By Jenkins27 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-28-2015, 07:24 PM
  2. [SOLVED] user form to input data according to text in textbox and listbox
    By a.hudrea in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-10-2014, 04:27 AM
  3. change textbox color on subform based on condition on another form
    By rlsublime in forum Access Programming / VBA / Macros
    Replies: 1
    Last Post: 01-16-2014, 10:04 PM
  4. User form textbox message for input error
    By microsmith in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-01-2007, 02:50 PM
  5. Userform-Change textbox color and font based on input in other tex
    By Neal in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-21-2005, 08:05 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