0

I have 100 plus different users that will use a certain program that will require different settings in a ini file. I was thinking that excel might be the best way to create these files and write them to a folder in individual files. The data should look like this.

All of this data will need to be in every text file:

UseMct=
UseCellular=
UseKvh=
UseIridium=
UseAurora=
UseSailor=
SailorUnitAddress=
AuroraUnitAddress=
QualcommSerialPort=
MctUnitAddress=
CellularUnitAddress=
KvhSerialPort=
KvhUnitAddress=
IridiumUnitAddress=
IridiumPositionUrl=
HostUrl=

The individual values for each of the following columns will have the required data. so Cell B1 will have the value for the first text file where the above data will be in column A.


UseMct=(value in B1)
UseCellular=(value in B2)
etc, etc.

The next text file will have all of these fields in A1 once again, but with this field mapping.


UseMct=(value in C1)
UseCellular=(value in C2)
etc, etc.

This would loop until the document is completed and would use a certain field as the filenames. Need help! Thanks.

I have looked at the following questions:
Outputting Excel rows to a series of text files
Write each Excel row to new .txt file with ColumnA as file name

Community
  • 1
  • 1
cadillacace
  • 86
  • 10
  • Make these the column names, populate your excel sheet, and then a small shell or similar script to write the CSV to different files would do. What have you tried, BTW? – Sudipta Chatterjee Sep 04 '13 at 22:21
  • Your mapping is a bit confusing. You have one that is in column c then column b but the next one is only in column c? Did you mean to put the first c1 as b1? – Jon49 Sep 04 '13 at 23:13
  • Which part of this *exactly* are you having a problem with? – Tim Williams Sep 04 '13 at 23:19
  • I see that you registered a second account with the same name in order to post a comment as an answer to your own question. This is not a good idea on multiple counts. 1. You can answer your own question with the same account, but if you have less than 100 rep there's an 8 hour waiting period. 2. Using the same account, you can edit your own posts without peer review. The edit you submitted with the second account that sat in the Suggested Edits queue for an hour waiting for approval would have appeared immediately if it had been submitted by the account that posted the question. – Adi Inbar Sep 05 '13 at 00:30
  • 3. "Answer" at StackOverflow means you're answering the question. It's not like "Reply" in a discussion forum. Your answer should have been a comment. Although you need at least 50 rep to comment on other people's posts, you can comment on your own posts regardless of rep - if you use the same account! – Adi Inbar Sep 05 '13 at 00:32
  • Sorry I used a work google apps account, must have used a personal one at home. I will work on that. – cadillacace Sep 05 '13 at 01:06

1 Answers1

2

You need something like this:

Sub iniCreate()

  For iCol = 1 To 3
    Open Environ("UserProfile") & "/MyProg" & Range("B1").Offset(0, iCol - 1).Value _
        & ".ini" For Output As #1
    For jRow = 1 To 16
      Print #1, Range("A2").Offset(jRow - 1, 0); Range("A2").Offset(jRow - 1, iCol)
    Next jRow
    Close #1
  Next iCol

End Sub

I used random numbers as data so it looked like this:

                    V000        V001        V002
UseMct=             0.659099708 0.098897863 0.66830137
UseCellular=        0.081138532 0.064777691 0.919835459
UseKvh=             0.942430093 0.872116053 0.032414535
UseIridium=         0.263586179 0.921751649 0.295967085
UseAurora=          0.867225038 0.094161678 0.11271394
UseSailor=          0.112345073 0.247013614 0.562920243
SailorUnitAddress=  0.641083386 0.630124454 0.430450477
AuroraUnitAddress=  0.133569751 0.431081763 0.620952387
QualcommSerialPort= 0.489904861 0.745152668 0.0371556
MctUnitAddress=     0.390312141 0.643551357 0.621789056
CellularUnitAddress=0.924394826 0.672907813 0.834973453
KvhSerialPort=      0.431335182 0.040557434 0.329205484
KvhUnitAddress=     0.018331225 0.405080112 0.281003
IridiumUnitAddress= 0.530083065 0.428947849 0.781832847
IridiumPositionUrl= 0.473567159 0.428633715 0.00044413
HostUrl=            0.132253798 0.832369002 0.981755331

The V000, V001 etc form part of the file name. E.g. MyProgV000.ini I use the UserProfile environment variable to select an output folder. You can choose another one if you prefer.

Then the two For Loops just output the data to the file.

RickXL
  • 36
  • 2
  • Rick, I believe this will work for me, thanks for your help. I'll let you know tomorrow. – cadillacace Sep 05 '13 at 01:06
  • Rick when using the vba code above with the data you supplied the files generated have the .ini properties repeated twice. For example, the first line of the generated file(s) is UseMct=UseMct=. – cadillacace Sep 05 '13 at 13:45
  • Profound apologies. I changed the values of i and j to iCol and jRow to make it slightly easier to understand. All would have been well if I had changed all of them. The above code should now be OK. That will teach me not to use Option Explicit. – RickXL Sep 05 '13 at 22:42
  • No problem! That worked great. Sincere thanks. I have learned alot by messing with it today. Didn't think to try and put iCol there :) – cadillacace Sep 06 '13 at 02:24