+ Reply to Thread
Results 1 to 4 of 4

Inputting values into an Array as Text from Text Input mode

Hybrid View

  1. #1
    Registered User
    Join Date
    05-23-2008
    Posts
    11

    Inputting values into an Array as Text from Text Input mode

    Hi Guys,

    I'm trying to get text into an array and then use it to form the basis of a folder location but I keep getting a mismatch error.


     
        SourceFolder = Application.InputBox("Enter Source Folder Name. Make sure you do not have any spaces at the end of the line and make sure the line ends with a \ (backslash)", "Source Folder Name", Type:=2)
        ArraySource = Application.InputBox("Enter in the list of file numbers, make sure they are separated by commas", "Enter Comma Separated List", Type:=2)
        EditedArray = Split(Trim(ArraySource), ",")
        FloorPlans = Array(EditedArray)
        Naming = "Floor Plan"
        Extension = ".xls"
        
        For K = 0 To UBound(FloorPlans)
        
        fullpathname = SourceFolder + Naming + FloorPlans(K) + Extension
        Set SrcBook = Workbooks.Open(fullpathname, UpdateLinks:=0)
    So basically, I have a folder of files eg
    Floor Plan A001.xls
    Floor Plan A002.xls
    ...
    Floor Plan Z999.xls

    And I want to selectively open and print a subset of files. So the first text input will take in the folder I'm after for example:
    "C:\Temp\"

    The second input will take in the numbers I want, for example,
    A001, B003, C005

    And I want it to generate the fullpath of "C:\Temp\Floor Plan A001.xls" so that Excel knows which file to open.

    I'm not sure how to assign my variables so that I don't get a mismatch error.

    Oh, the reason why I need to do it in this manner is because I need to open and print files in a specific order.

    I didn't include the rest of the macro where it prints etc, but basically, I don't need the entire folder, I just need to print specific files from it in a specific order governed by the input.

    Any ideas on how to do it?
    Thanks!
    J
    Last edited by romperstomper; 10-04-2010 at 09:07 AM. Reason: mark solved

  2. #2
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Inputting values into an Array as Text from Text Input mode

    Try this
        SourceFolder = Application.InputBox("Enter Source Folder Name. Make sure you do not have any spaces at the end of the line and make sure the line ends with a \ (backslash)", "Source Folder Name", Type:=2)
        If Not Right(SourceFolder, 1) = "\" Then SourceFolder = SourceFolder & "\"
        
        ArraySource = Application.InputBox("Enter in the list of file numbers, make sure they are separated by commas", "Enter Comma Separated List", Type:=2)
        FloorPlanArray = Split(Trim(ArraySource), ",")
    
        Naming = "Floor Plan"
        Extension = ".xls"
    
        For K = 0 To UBound(FloorPlanArray)
            fullpathname = SourceFolder + Naming + FloorPlanArray(K) + Extension
            Set SrcBook = Workbooks.Open(fullpathname, UpdateLinks:=0)
            ' More code here?
        Next

    You might need
    Naming = "Floor Plan "
    (Note the trailing space)
    To concatenate your file name.

    Hope this helps
    Last edited by Marcol; 10-04-2010 at 07:49 AM.
    If you need any more information, please feel free to ask.

    However,If this takes care of your needs, please select Thread Tools from menu above and set this topic to SOLVED. It helps everybody! ....

    Also
    اس کی مدد کرتا ہے اگر
    شکریہ کہنے کے لئے سٹار کلک کریں
    If you are satisfied by any members response to your problem please consider using the small Star icon bottom left of their post to show your appreciation.

  3. #3
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Inputting values into an Array as Text from Text Input mode

    Why don't you use:

    Sub snb()
      For Each fl In Application.GetOpenFilename(",*.xls", , , , True)
        Workbooks.Open fl
      Next
    End Sub



  4. #4
    Registered User
    Join Date
    05-23-2008
    Posts
    11

    Re: Inputting values into an Array as Text from Text Input mode

    I actually worked out what the bug was in my code. I double used the array by accident not knowing the split returns an array.

    I couldn't use the get folder because it I needed to print in the order that the input values were placed in. So if i grabbed the folder, it would print in numerical order and that wasn't what I needed.

    Thanks heaps for the responses though!

    Marcol, thanks heaps!! It was your code that made me realise that I doubled up on the array
    Last edited by nyum; 10-04-2010 at 08:39 AM.

+ 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