tamatea2010
New Member
- Joined
- Apr 22, 2019
- Messages
- 6
Hello,
I need a vba code to copy some text lines extracted from an Excel sheet at a specific position inside an existing text (*.cfg) file.
Lines to be copied from active sheet, cell J2 to J20 :
[fltsim.x]
title=Carenado AT45 Air Tahiti (F-ORVA, "Te Maru Ata")
sim=AT45
texture=VTA_F-ORVA
atc_airline=AIR TAHITI
atc_id=F-ORVA
atc_flight_number=001
atc_heavy=0
atc_parking_types=GATE,RAMP,CARGO
atc_parking_code=VTA
atc_id_color=0000000000
ui_manufacturer=Avions de Transport Régional
ui_type=AT45
ui_variation=Air Tahiti (F-ORVA, "Te Maru Ata")
ui_typerole=Twin Engine TurboProp
ui_createdby=Carenado
version=1.1
visual_damage=1
description=Carenado\nATR 42-500. Repaint by Yann MAESTRATI.
Destination text file path :
"C:\Program Files\Lockheed Martin\Prepar3D v4\SimObjects\Airplanes\Carenado AT45\Aircraft.cfg"
Destination text file content :
//*********************************************************
// Carenado A42-500 FSX/P3D
// Copyright © Carenado 2019 - All Rights Reserved
//*********************************************************
[fltsim.0]
title=Carenado A42-500 HOUSE LIVERY
sim=AT45
ui_manufacturer="Carenado"
ui_type=AT42
ui_typerole="Twin Engine TurboProp"
ui_createdby="Carenado"
ui_variation="HOUSE LIVERY"
description="Carenado A42-500"
atc_heavy=0
atc_id_color=0000000000
visual_damage=1
[fltsim.1]
title=Carenado A42-500 D-BCJC
sim=AT45
texture=D-BCJC
atc_id=D-BCJC
ui_manufacturer="Carenado"
ui_type=AT42
ui_typerole="Twin Engine TurboProp"
ui_createdby="Carenado"
ui_variation="D-BCJC"
description="Carenado A42-500"
atc_heavy=0
atc_id_color=0000000000
visual_damage=1
[General]
atc_type=ATR
atc_model=AT45
editable=0
What is needed :
1- the code will read the text file and search for the last [fltsim.x] block
2- then it will read the "x" value, "1" in the exemple
3- then it will upadate the "x" amount of J2 cell value from "x" to "x+1", in the exemple J2 cell value will be changed from [fltsim.x] to [fltsim.2]
4- then it will copy all the lines (J2 to J20 cells values) and insert them inside the text file, after the last [fltsim.x] block, in the exemple after [fltsim.1] block
Expected text file content :
//*********************************************************
// Carenado A42-500 FSX/P3D
// Copyright © Carenado 2019 - All Rights Reserved
//*********************************************************
[fltsim.0]
title=Carenado A42-500 HOUSE LIVERY
sim=AT45
ui_manufacturer="Carenado"
ui_type=AT42
ui_typerole="Twin Engine TurboProp"
ui_createdby="Carenado"
ui_variation="HOUSE LIVERY"
description="Carenado A42-500"
atc_heavy=0
atc_id_color=0000000000
visual_damage=1
[fltsim.1]
title=Carenado A42-500 D-BCJC
sim=AT45
texture=D-BCJC
atc_id=D-BCJC
ui_manufacturer="Carenado"
ui_type=AT42
ui_typerole="Twin Engine TurboProp"
ui_createdby="Carenado"
ui_variation="D-BCJC"
description="Carenado A42-500"
atc_heavy=0
atc_id_color=0000000000
visual_damage=1
[fltsim.2]
title=Carenado AT45 Air Tahiti (F-ORVA, "Te Maru Ata")
sim=AT45
texture=VTA_F-ORVA
atc_airline=AIR TAHITI
atc_id=F-ORVA
atc_flight_number=001
atc_heavy=0
atc_parking_types=GATE,RAMP,CARGO
atc_parking_code=VTA
atc_id_color=0000000000
ui_manufacturer=Avions de Transport Régional
ui_type=AT45
ui_variation=Air Tahiti (F-ORVA, "Te Maru Ata")
ui_typerole=Twin Engine TurboProp
ui_createdby=Carenado
version=1.1
visual_damage=1
description=Carenado\nATR 42-500. Repaint by Yann MAESTRATI.
[General]
atc_type=ATR
atc_model=AT45
editable=0
I need a vba code to copy some text lines extracted from an Excel sheet at a specific position inside an existing text (*.cfg) file.
Lines to be copied from active sheet, cell J2 to J20 :
[fltsim.x]
title=Carenado AT45 Air Tahiti (F-ORVA, "Te Maru Ata")
sim=AT45
texture=VTA_F-ORVA
atc_airline=AIR TAHITI
atc_id=F-ORVA
atc_flight_number=001
atc_heavy=0
atc_parking_types=GATE,RAMP,CARGO
atc_parking_code=VTA
atc_id_color=0000000000
ui_manufacturer=Avions de Transport Régional
ui_type=AT45
ui_variation=Air Tahiti (F-ORVA, "Te Maru Ata")
ui_typerole=Twin Engine TurboProp
ui_createdby=Carenado
version=1.1
visual_damage=1
description=Carenado\nATR 42-500. Repaint by Yann MAESTRATI.
Destination text file path :
"C:\Program Files\Lockheed Martin\Prepar3D v4\SimObjects\Airplanes\Carenado AT45\Aircraft.cfg"
Destination text file content :
//*********************************************************
// Carenado A42-500 FSX/P3D
// Copyright © Carenado 2019 - All Rights Reserved
//*********************************************************
[fltsim.0]
title=Carenado A42-500 HOUSE LIVERY
sim=AT45
ui_manufacturer="Carenado"
ui_type=AT42
ui_typerole="Twin Engine TurboProp"
ui_createdby="Carenado"
ui_variation="HOUSE LIVERY"
description="Carenado A42-500"
atc_heavy=0
atc_id_color=0000000000
visual_damage=1
[fltsim.1]
title=Carenado A42-500 D-BCJC
sim=AT45
texture=D-BCJC
atc_id=D-BCJC
ui_manufacturer="Carenado"
ui_type=AT42
ui_typerole="Twin Engine TurboProp"
ui_createdby="Carenado"
ui_variation="D-BCJC"
description="Carenado A42-500"
atc_heavy=0
atc_id_color=0000000000
visual_damage=1
[General]
atc_type=ATR
atc_model=AT45
editable=0
What is needed :
1- the code will read the text file and search for the last [fltsim.x] block
2- then it will read the "x" value, "1" in the exemple
3- then it will upadate the "x" amount of J2 cell value from "x" to "x+1", in the exemple J2 cell value will be changed from [fltsim.x] to [fltsim.2]
4- then it will copy all the lines (J2 to J20 cells values) and insert them inside the text file, after the last [fltsim.x] block, in the exemple after [fltsim.1] block
Expected text file content :
//*********************************************************
// Carenado A42-500 FSX/P3D
// Copyright © Carenado 2019 - All Rights Reserved
//*********************************************************
[fltsim.0]
title=Carenado A42-500 HOUSE LIVERY
sim=AT45
ui_manufacturer="Carenado"
ui_type=AT42
ui_typerole="Twin Engine TurboProp"
ui_createdby="Carenado"
ui_variation="HOUSE LIVERY"
description="Carenado A42-500"
atc_heavy=0
atc_id_color=0000000000
visual_damage=1
[fltsim.1]
title=Carenado A42-500 D-BCJC
sim=AT45
texture=D-BCJC
atc_id=D-BCJC
ui_manufacturer="Carenado"
ui_type=AT42
ui_typerole="Twin Engine TurboProp"
ui_createdby="Carenado"
ui_variation="D-BCJC"
description="Carenado A42-500"
atc_heavy=0
atc_id_color=0000000000
visual_damage=1
[fltsim.2]
title=Carenado AT45 Air Tahiti (F-ORVA, "Te Maru Ata")
sim=AT45
texture=VTA_F-ORVA
atc_airline=AIR TAHITI
atc_id=F-ORVA
atc_flight_number=001
atc_heavy=0
atc_parking_types=GATE,RAMP,CARGO
atc_parking_code=VTA
atc_id_color=0000000000
ui_manufacturer=Avions de Transport Régional
ui_type=AT45
ui_variation=Air Tahiti (F-ORVA, "Te Maru Ata")
ui_typerole=Twin Engine TurboProp
ui_createdby=Carenado
version=1.1
visual_damage=1
description=Carenado\nATR 42-500. Repaint by Yann MAESTRATI.
[General]
atc_type=ATR
atc_model=AT45
editable=0