-1
Excel 2003에서 완벽하게 잘 작동하는 통합 문서를 내보내는 매크로가 있습니다. 그러나 2007 또는 2010 컴퓨터에서는 작동하지 않습니다. 그것은 실행하고 Save As
상자를 엽니 다,하지만 내가 입력하면, 내가 확인을 클릭하면, 그냥 거기 앉아있다. 저장하려면 Ok
을 클릭해도 아무런 변화가 없습니다. 누군가 제발 도와 드릴까요?매크로는 2007 년이 아니라 Excel 2003에서 작동합니다.
코드 : 다른 위치로 시트를 복사 한 경우이 코드의
이Sub ExportReports()
Dim fdialog As Office.FileDialog
Dim varfile As String
Static varfile_name As String
Dim curr_wb_name As String
Dim num_sheets As Integer
Dim xflag As String
Dim openflag As Boolean
Static strpassword As String
'check to see if invoice has been moved
'check to see if all programs report has been moved
'move specified report
'User selects the file containing the budget - must be in set format
'Changes to the format of budget spreadsheet are likely to affect this code
curr_wb_name = ActiveWorkbook.Name
prog_name = ActiveWorkbook.Worksheets("Menu").Range("F14")
lineselectfile:
Set fdialog = Application.FileDialog(msoFileDialogFilePicker)
With fdialog
.Title = "Please select or create the file you wish to export reports to"
.Filters.Clear
.Filters.Add "Microsoft Excel Files", "*.xlsx"
If .Show = True Then
varfile = .SelectedItems(1)
Else
Exit Sub
'MsgBox "You must select a file to import, please try again", _
' vbOKOnly, "Import Error!"
'GoTo lineselectfile
End If
End With
If strpassword = "" Then
strpassword = InputBox("Enter a password to protect worksheets in this file")
End If
n = 0
For n = 1 To Workbooks.Count
If Workbooks(n).Name = varfile_name Then
openflag = True
Workbooks(n).Activate
End If
Next
If openflag = False Then
Workbooks.Open Filename:=varfile, UpdateLinks:=0
End If
varfile_name = ActiveWorkbook.Name
num_sheets = Workbooks.Count
'n = 0
xflag = "a"
'Do Until n = num_sheets
If Sheets(1).Name = "Invoice" Then
xflag = xflag & "b"
End If
If Sheets(2).Name = "All Programs" Then
xflag = xflag & "c"
End If
'n = n + 1
'Loop
Select Case xflag
Case "a" ' Both Invoice and All Programs must be exported
Windows(curr_wb_name).Activate
Sheets("Invoice").Select
Sheets("Invoice").Copy before:=Workbooks(varfile_name).Sheets(1)
Cells.Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False _
, Transpose:=False
ActiveSheet.Protect Password:=strpassword, Scenarios:=True
Range("a1").Select
Windows(curr_wb_name).Activate
Sheets("Preview All Programs").Select
Sheets("Preview All Programs").Copy before:=Workbooks(varfile_name).Sheets(2)
Cells.Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False _
, Transpose:=False
Sheets("Preview All Programs").Name = "All Programs"
ActiveSheet.Protect Password:=strpassword, Scenarios:=True
Range("a1").Select
Case "ab" ' Only All Programs must be exported
Windows(curr_wb_name).Activate
Sheets("Preview All Programs").Select
Sheets("Preview All Programs").Copy After:=Workbooks(varfile_name).Sheets(2)
Cells.Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False _
, Transpose:=False
Sheets("Preview All Programs").Name = "All Programs"
ActiveSheet.Protect Password:=strpassword, Scenarios:=True
Range("a1").Select
Case "ac" ' Only invoice must be exported
Windows(curr_wb_name).Activate
Sheets("Invoice").Select
Sheets("Invoice").Copy After:=Workbooks(varfile_name).Sheets(1)
Cells.Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False _
, Transpose:=False
ActiveSheet.Protect Password:=strpassword, Scenarios:=True
Range("a1").Select
End Select
Windows(curr_wb_name).Activate
Sheets("Preview").Select
Sheets("Preview").Copy After:=Workbooks(varfile_name).Sheets(2)
Cells.Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False _
, Transpose:=False
Sheets("Preview").Name = prog_name
ActiveSheet.Protect Password:=strpassword, Scenarios:=True
Range("a1").Select
Windows(curr_wb_name).Activate
Worksheets("Menu").Activate
'Workbooks(varfile_name).Close
End Sub
+1 좋은 일 많은 코드들 사이에서 좋은 팁을 발견! – aevanko
답장을 보내 주셔서 감사합니다. 몇 년 전에 우리를 위해했던 사람은 코드에 대해 아무 것도 모른다. 코드에서 어디에서 작동하는지 확인하기 위해 제안 사항을 넣을 수 있습니까? – Maz
@user : 내게 통합 문서를 보내고 싶다면 그것을 고치려고 노력할 것입니다. t i m j j w i l l i a m s {at} g ma i {.com} –