mg.SourceTableName =worksheet.Name ' 指定要合并的表
改成
mg.SourceTableName =worksheet.Name.replace("$", "") & "$"