Page 1 of 2 12 LastLast
Results 1 to 15 of 23
  1. #1
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Write in a txt in a specify position (2000 sr 1)

    I have this sheet with a value:
    SIA
    ABI
    CAB
    C/C

    Is possible to write the value refered in the column B... in a txt file?

    Example:
    The file attached contain many line:
    The macro i need:

    Get the value of filed SIA from sheet (in this case ABSC5) and write into all line identified with the 10000000 in a position 92 to 96 (owerite existis value)

    Get the value of filed SIA from sheet (in this case ABSC5) and write into line identified with the first 2 character PC or EF in a position 4 to 8 (owerite existis value)

    Tks in advance

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Write in a txt in a specify position (2000 sr 1)

    See attached code. Change the path of the file in the constants.

  3. #3
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Write in a txt in a specify position (2000 sr 1)

    kiss.!

  4. #4
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Write in a txt in a specify position (2000 sr 1)

    My friend...
    If i would want to write the same structure of txt file attached in a new blank txt file... and fill this with a string line with the value present i a shett...
    Example:
    Into sheet in range A2 B7 is a fixed value.
    Into range C:H are present the information for every users
    Each user is composed with 7 blok of value

    10000000
    20000000
    30000000
    40000000
    50000000
    70000000
    the value in column D write in line 10000000 max lenght 5 postion 70-74
    the value in comun C write in line 30000000 max lengh 30 position 11-40
    ....ecc. ecc...
    the line with 70000000 is blank for all users but required.

    in this case the users are only 2 but is possible a variuos number.
    Increase for each user of 1 to separate and identify the signle users
    Generate for eache users the famous blok of information ad in head and end file...

    If you suggest me only a write line with twoo users...

    the name of output file choice you;-)

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Write in a txt in a specify position (2000 sr 1)

    There is much more information in the text file you attached, I don't know how to generate that from the worksheet.

  6. #6
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Write in a txt in a specify position (2000 sr 1)

    Naturally you want to help me... and i help you to help me.;-)
    I have simplfy all information.... if for you is simple in this mode.
    Tks always for help.

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Write in a txt in a specify position (2000 sr 1)

    Here you go.

  8. #8
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Write in a txt in a specify position (2000 sr 1)

    Naturally...WORK FINE!
    Peraphs i have a little question to understand the posistion and alling string...
    I test and if i have difficult i call you...permit?
    Tks, Brother.
    Sal.

  9. #9
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Write in a txt in a specify position (2000 sr 1)

    Hans, first explain the string above, to understabd the tecnique to set the line with the number 22 (Space(22 - Len...) and 5 ( - 5) ...)

    strLine = " 10000000" & (lngRow - 1) & Space(22 - Len(Range("C" & lngRow))) & Range("C" & lngRow)
    strLine = strLine & Space(lngLength - Len(strLine) - 5) & Format(Range("B2"), "00000")
    Print #f, strLine

  10. #10
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Write in a txt in a specify position (2000 sr 1)

    I don't know if it is correct, since you haven't explained exactly what the structure of the text file is. The start of the second line in Simple.txt is
    <pre>"100000001 AAAAAAAAAAAAAAAA"
    </pre>

    The code Space(22 - Len(Range("C" & lngRow))) & Range("C" & lngRow) makes sure that the total length of
    <pre>" AAAAAAAAAAAAAAAA"
    </pre>

    is 22 characters: it takes the text from a cell in column C, in this case 16, and places 22-16 = 6 spaces before it. If the text had been 13 characters in length, it would have inserted 22-13 = 9 spaces, so that the total length is 22 again.

    The whole line is made exactly lngLength characters long, with the 5 characters from cell B2 at the end.

  11. #11
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Write in a txt in a specify position (2000 sr 1)

    First error.... OBJCET REQUIRED
    For the record signed with 10000000 i have errorr. In effect in postion 70-74 i would want to insert the value of column D and in position 75-79 insert and would want to insert the value of column E for each list of users....

  12. #12
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Write in a txt in a specify position (2000 sr 1)

    You have this code:

    ... Format(Range("D" & lngRow), "00000").Text & Format(Range("E" & lngRow), "00000").Text ...

    Format results in a string, you should not put .Text after it. Change the line to

    strLine = strLine & Space(69 - Len(strLine)) & Format(Range("D" & lngRow), "00000") & Format(Range("E" & lngRow), "00000")

    The number 69 ensures that the value from column D starts in position 70.

  13. #13
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Write in a txt in a specify position (2000 sr 1)

    acccccccccccccc..... i am a stupid!

  14. #14
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Write in a txt in a specify position (2000 sr 1)

    After the number "3" (is fixed for each users, position 97) i would want to insert the value of column K is a misc of text and number in position 98-113
    And in to position 120 a fixed value "E", for each users.
    ... patience:-)

    strLine = " 10000000" & (lngRow - 1) & " " & "000000" & Range("B6").Text & CAUS & Format(Range("D" & lngRow), "00000000000000") & "+" & Range("B3").Text & Range("B4").Text & Range("B5").Text
    strLine = strLine & Space(69 - Len(strLine)) & Format(Range("D" & lngRow), "00000") & Format(Range("E" & lngRow), "00000") & Range("F" & lngRow).Text
    strLine = strLine & Space(lngLength - Len(strLine) - 29) & Range("B2") & "3"
    Print #f, strLine

  15. #15
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Write in a txt in a specify position (2000 sr 1)

    Try this:

    strLine = " 10000000" & (lngRow - 1) & " " & "000000" & Range("B6").Text & CAUS & Format(Range("D" & lngRow), "00000000000000") & "+" & Range("B3").Text & Range("B4").Text & Range("B5").Text
    strLine = strLine & Space(69 - Len(strLine)) & Format(Range("D" & lngRow), "00000") & Format(Range("E" & lngRow), "00000") & Range("F" & lngRow).Text
    strLine = strLine & Space(lngLength - Len(strLine) - 29) & Range("B2") & "3" & Range("K" & lngRow)
    strLine = strLine & Space(6) & "E"
    Print #f, strLine

Page 1 of 2 12 LastLast

Posting Permissions

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