Hi,
I'm now trying to combine multiples excel sheets from multiple excel files. I want to get one excel file with respective sheets as combine. These excel files are in the same folder. The variables for each sheet of each excel file are the same.

My code is below and the sample excels files and combined file at the attachment.

I'm trying the below code, the result is not the way that I want, please suggest me.


local xlsx : dir "$outputs\fb"files"*.xlsx"
di `xlsx'



import excel using "$outputs\fb\hfc_outputs_hvs_sup_22_1sep2020.xlsx" , desc
return list
local worksheets `r(N_worksheet)'
display `worksheets'

*set trace on

forvalues i = 1 / `worksheets' {
display " Sheet number `i'"
local shtname`i' `r(worksheet_`i')'
display "loading sheet: `r(worksheet_`i')'"

tempfile ts`i'
save `ts`i'', replace emptyok

foreach f in `xlsx' {
*set trace on

import excel using "$outputs/fb/`f'", sheet("`shtname`i''") firstrow clear
destring value, replace
*set trace on
display "file: `f' and sheet: `shtname`i''"


append using `ts`i''
save `ts`i'',replace


}
export excel using "$outputs/fb/com/combine_hfc_feedback.xlsx", sheet("`shtname`i''") sheetreplace firstrow(var)
}