一、Excel宏代码(一)转换文件格式代码 ,我来为大家科普一下关于通过宏代码给工作表添加宏:如何将多个工作簿的首个工作表合并到同一个工作簿中?下面希望有你要的答案,我们一起来看看吧!

通过宏代码给工作表添加宏:如何将多个工作簿的首个工作表合并到同一个工作簿中

通过宏代码给工作表添加宏:如何将多个工作簿的首个工作表合并到同一个工作簿中

一、Excel宏代码

(一)转换文件格式代码

ren *.xlsx *.xls

(二)宏代码

Sub merge() Dim fd As FileDialog Set fd = Application.FileDialog(msoFileDialogFilePicker) Dim newwb As Workbook Set newwb = Workbooks.Add With fd If .Show = -1 Then Dim vrtSelectedItem As Variant Dim i As Integer i = 1 For Each vrtSelectedItem In .SelectedItems Dim tempwb As Workbook Set tempwb = Workbooks.Open(vrtSelectedItem) tempwb.Worksheets(1).Copy Before:=newwb.Worksheets(i) newwb.Worksheets(i).Name = VBA.Replace(tempwb.Name, ".xlsx", "") tempwb.Close SaveChanges:=False i = i 1 Next vrtSelectedItem End If End With Set fd = Nothing End Sub

二、WPS宏代码

(一)转换文件格式代码

ren *.xls *.et ren *.xlsx *.et

(二)宏代码

function 合并工作簿中第一个工作表(){ var twb=ThisWorkbook; var pah=twb.Path; var str=pah "\\*.et"; var fn=Dir(str); while(fn!=twb.Name){ Workbooks.Open(pah "\\" fn); var awb=ActiveWorkbook awb.Sheets(1).Copy(null,twb.Sheets(twb.Sheets.Count)); awb.Close(false); try{ fn=Dir(); } catch(err){break} } }

,