Macro to generate a c++ header file using excel

Sijith

New Member
Joined
Feb 19, 2014
Messages
2
Hi all,

I am new to this foruma nd it looks great for me :)

I am thinking to make a excel file which can generate a headre file for my c++ source file.
Previoulsy we used to generate .h files using excel but i dont know the logic behind that(Hope some macros using for that).

MY header file contains this many data and my intention is to give "MYapp Alpha 0.0.3" through excel file because the version number changes for each release. If i used excel file then I can edit that excel and it creates .h file for me, later some more informations i can make configurable through excel file

#define APP_FLASH_APP_ID 0x123
#define APP_VERSION_NUM "MYapp Alpha 0.0.3 "
#define APP_PRODUCT_NAME "TPI "
#define APP_DESCRIPTION_STR APP_PRODUCT_NAME APP_VERSION_NUM
#define APP_RELEASE_DATE_STR "10/11/13"
#define APP_SOFTWARE_PARTNUM_LEN 10

Some valuable help or suggestions needed

Have a great day
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Hi Sijith,

Yes, this is easy to do in Excel. But there are a few options for you to consider before providing a solution:

Where (what path or folder) should the .h be placed?

- do you want it placed in the current (Excel) working folder? Or,

- do you have a fixed folder location? Or,

- would you like to browse for the .h file folder (like using a Save file dialog)?

Do you want "MYapp Alpha 0.0.3" read from a cell in Excel so you can edit it there before generating the .h file?

You mention other information you want to make configurable through Excel. Do you want to handle it the same way?

Anyway, just rest assured that it is quite easy in Excel to write a text file (such as a .h file).

Damon
 
Upvote 0
I like to keep it in a fixed location say "c:/user/mydata" and dont want user to browse the location where it saved using excel.

Like to keep "MYapp Alpha 0.0.3" in a cell in Excel so as u suggested I can edit any time I needed.

My real need is to save it in 2 files one *.h and other *.opt. Both are fixed location.
 
Upvote 0
Hi again Sijith,

Okay, suppose you have path, filename, and version number in cells B1:B3 like this:

.... A .......| ....... B ..........
Path: .......| C:/user/mydata
File: ........| MyFile
Version: ...| "MYapp Alpha 0.0.3"

Then you can use this code to generate the .h and .opt files in the requested folder (path)

Code:
Sub WriteHeaderFiles()
   Dim Fpath      As String
   Dim Fname      As String
   Dim Fversion   As String
   
   Fversion = Range("B3")
   
   'set path to folder
   Fpath = Range("B1")
   If Right(Fpath, 1) <> "\" Then Fpath = Fpath & "\"
   
   'add filename to folder name to get complete path
   Fname = Range("B2")
   Fpath = Fpath & Fname
     
   'write .h file
   
   Open Fpath & ".h" For Output As #1
   
   Print #1, "#define APP_FLASH_APP_ID 0x123"
   Print #1, "#define APP_VERSION_NUM " & Fversion
   Print #1, "#define APP_PRODUCT_NAME ""TPI"""
   Print #1, "#define APP_DESCRIPTION_STR APP_PRODUCT_NAME APP_VERSION_NUM"
   Print #1, "#define APP_RELEASE_DATE_STR ""10/11/13"""
   Print #1, "#define APP_SOFTWARE_PARTNUM_LEN 10"
   
   Close #1
   
   'write .opt file
   
   Open Fpath & ".opt" For Output As #2
   
   Print #2, "#define APP_FLASH_APP_ID 0x123"   
   Print #2, "#define APP_VERSION_NUM " & Fversion
   Print #2, "#define APP_PRODUCT_NAME ""TPI"""
   Print #2, "#define APP_DESCRIPTION_STR APP_PRODUCT_NAME APP_VERSION_NUM"
   Print #2, "#define APP_RELEASE_DATE_STR ""10/11/13"""
   Print #2, "#define APP_SOFTWARE_PARTNUM_LEN 10"
   
   Close #2
End Sub

Please note that you do not enclose the path and file name in quotes, but do enclose the version in quotes.

Keep Excelling.

Damon
 
Last edited:
Upvote 0

Forum statistics

Threads
1,213,546
Messages
6,114,251
Members
448,556
Latest member
peterhess2002

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top