Question

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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top