我制作了一个执行一些重复任务的宏(更新某些数据连接并将此信息传输到另一个Excel)。代码工作正常,但是,有时,它会更改工作表中某些单元格的格式,甚至在宏中都不会调用。
这听起来像个错误。我之前遇到了同样的问题,通过删除On Error Resume Next
行解决了这个问题。
请您阅读我的代码,看看是否有可能导致此错误的内容?我真的不能丢失我的格式,因为我正在使用这些表格来处理重要的公司报告。
这是我的代码:
Sub TRANSFER_INPUT()
'
' TRANSFER_INPUT Macro
'
Dim MWWorkBook As Workbook
Set MWWorkBook = ActiveWorkbook
Sheets("PAR").Select
Dim Pateka As String
Worksheets("PAR").Activate
Pateka = Range("E5").Value
Dim Datum1 As String
Worksheets("PAR").Activate
Datum1 = Range("E6").Value
Dim InputExcel As Workbook
Workbooks.Open Filename:=Pateka & "INPUT" & Datum1 & ".xlsx", UpdateLinks:=3
Set InputExcel = ActiveWorkbook
'###
'MAIN WORKBOOK / PREFRLANJE FAJLOVI
'###
'INPUTBILANS
MWWorkBook.Activate
Sheets("INPUTBILANS").Select
Range("F11:M1000").Select
Selection.Copy
Range("Y11").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
'REFRESH BILANS VO INPUT
MWWorkBook.Activate
Sheets("INPUTBILANS").Select
Range("F10").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
'###
'###
'PREFRLI VO INPUT
'###
'###
'Kopiraj Bilans_1
Range("F11:V1000").Select
Selection.Copy
'Pastiraj Bilans_1 VO INPUT / Bilans_1 vo Bilans_2
InputExcel.Activate
Sheets("BILANS_1").Select
Range("B8").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Range("B8:R1000").Select
Selection.Copy
Sheets("BILANS_2").Select
Range("B8").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
''' PREFRLI I KOPIRAJ COSTS
MWWorkBook.Activate
Sheets("COSTS").Select
Range("A4").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
Range("A5:AV312").Select
Selection.Copy
InputExcel.Activate
Sheets("COSTS").Activate
Range("A5").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
'Kopiraj OPER.COST
MWWorkBook.Activate
Sheets("OPER.COST | NONOP | PRIHODI").Select
Range("D7").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
Range("G16:P63").Select
Selection.Copy
InputExcel.Activate
Sheets("OPER.COST").Select
Range("Z4").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
'Kopiraj PRIHODI
MWWorkBook.Activate
Sheets("OPER.COST | NONOP | PRIHODI").Select
Range("D65:F204").Select
Selection.Copy
InputExcel.Activate
Sheets("PRIHODI").Select
Range("B4").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
'Kopiraj NONOP
MWWorkBook.Activate
Sheets("OPER.COST | NONOP | PRIHODI").Select
Range("F8:F14").Select
Selection.Copy
InputExcel.Activate
Sheets("NONOP").Select
Range("D5").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
End Sub
非常感谢你!