我不知道为什么你需要一个exe文件。 下面的代码是在Excel中的一个模块与扩展.XLSM文件,比方说CopySheets.xlsm。
将一个CommandButton添加到user_form(或者如果它更容易,可能在其中一张表中),并且在该文件的模块中包含以下代码。
Option Explicit
Dim a As Workbook
Dim b As Workbook
Dim txt As String
Dim sht As Worksheet
Sub Button1_Click()
Set a = Workbooks.Open("\\DESKTOP-E8QK413\Videos\target.xlsx.xlsx")
' (Filename in brackets must have full path and .xlsx extension)'
Set b = Workbooks.Open(AddWorkbookPath"Book1.xlsx")
txt = InputBox("Select Sheet name to Copy")
' loop through workbook a sheets and check is txt is found
For Each sht In a.Sheets
' sheet exists in workbook a
If txt = sht.Name Then
MsgBox "Sheet " & txt & " found in workbook " & a.Name
GoTo Proceed_Copy
End If
Next sht
' error message - sheet not found in worbook a
MsgBox "Sheet " & txt & " NOT found in workbook " & a.Name
' close both workbooks in case sheet name was not found
a.Close
b.Close
End
Proceed_Copy:
a.Sheets(txt).Copy after:=b.Sheets(1)
a.Close
b.Close (xlSaveChanges)
End Sub