2016-07-26 2 views
0

Excel의 Txt 시트를 클라이언트의 B를 능가하는 서버에 복사하고 .exe 파일을 만들어야합니다. 매크로에서 실행 한이 코드는 xlsx를 능가합니다. 그것은 효과가 있었다. 하지만 XLtoEXE.exe를 http://orlando.mvps.org/XLtoEXEMore.asp에서 사용하면 파일을 exe로 변환 할 수 있습니다. 그런 다음 exe에서 다시 실행합니다. 그것은 작동하지 않았다. 내게 이유를 말해줘? 어떻게이 문제를 해결할 수 있습니까? 당신이 EXE 파일이 필요한 이유서버에서 클라이언트로 엑셀에서 시트를 복사하는 방법

Dim a As Workbook 
Dim b As Workbook 
Dim txt As String 


Sub Button1_Click() 
txt = InputBox("sheet name") 
MsgBox txt 
Set a = Workbooks.Open(Filename:="\\DESKTOP-E8QK413\Videos\target.xlsx.xlsx") 
Set b = Workbooks("book1.xlsx") 
a.Sheets(txt).Copy after:=b.Sheets(1) 
a.Close 

End Sub 

enter image description here

+0

어떤 라인 오류가 발생합니까? 'Workbooks ("book1.xlsx")'가 이미 열려 있습니까? 그렇지 않으면 먼저 열어야합니다. 열려있는 경우 'Set b = Workbooks ("book1")' –

+0

업데이트가 있어야합니다. 문제가 해결 되었습니까? –

+0

늦게 답장을 드려 죄송합니다. 에러 라인은'a.Sheets (txt) .Copy after : = b.Sheets (1)'입니다. 이 코드는 book1.exe –

답변

0

나는 확실하지 않다. 아래 코드는 확장 파일 .xlsm이있는 Excel 파일의 모듈에 있습니다. 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 
관련 문제