我创建了一个宏,它打开一个Excel文件并将其现有的外部链接更改为新的。在这个过程结束时,链接的一切都很好,但是,我可以看到宏以某种方式改变了某些工作簿中某些单元格的格式(例如从自定义格式到会计)。由于我正在使用的Excel文件有很多不同的工作簿和单元格,我真的需要格式化以保持静态,因为我打印Sheets作为报告,它们不应该看起来很奇怪。
这是我的代码 - 您可以清楚地看到它甚至不会划分单元格格式。什么可能导致这个问题的想法?
谢谢!
Sub ChangeLinksMacroINPUT()
Dim Mesec As String
Mesec = Range("E7").Value
Dim MesecEC As String
MesecEC = Range("F7").Value
Dim Godina As String
Godina = Range("E6").Value
Dim GodinaC As String
GodinaC = Range("F6").Value
Dim PrethodnaGodina As String
PrethodnaGodina = Range("E4").Value
Dim PrethodenMesec As String
PrethodenMesec = Range("E5").Value
Dim PredPrethodenMesec As String
PredPrethodenMesec = Range("E8").Value
Dim OsnovnaPateka As String
OsnovnaPateka = "Y:\AM\20" & Godina & "\"
On Error Resume Next
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.DisplayAlerts = False
Dim VariableWB As Workbook
Workbooks.Open Filename:="Y:\AM\20" & Godina & "\INPUT_" & Godina & "\INPUT" & Godina & Mesec & ".xlsx", UpdateLinks:=0
Set VariableWB = ActiveWorkbook
Sheets("PAR").Select
Range("D3").Value = MesecEC
Range("D5").Value = GodinaC
'*****INPUT Minus edna godina*****
ActiveWorkbook.ChangeLink Name:="Y:\AM\20" & PrethodnaGodina & "\INPUT_" & PrethodnaGodina & "\INPUT" & PrethodnaGodina & PrethodenMesec & ".xlsx", NewName:= _
"Y:\AM\20" & PrethodnaGodina & "\INPUT_" & PrethodnaGodina & "\INPUT" & PrethodnaGodina & Mesec & ".xlsx", Type:=xlExcelLinks
'*****INPUT Minus eden mesec*****
ActiveWorkbook.ChangeLink Name:="Y:\AM\20" & Godina & "\INPUT_" & Godina & "\INPUT" & Godina & PredPrethodenMesec & ".xlsx", NewName:= _
"Y:\AM\20" & Godina & "\INPUT_" & Godina & "\INPUT" & Godina & PrethodenMesec & ".xlsx", Type:=xlExcelLinks
'*****INV MOVEMENT*****
ActiveWorkbook.ChangeLink Name:="Y:\AM\20" & Godina & "\INV_" & Godina & "\Inv_mvmt_" & PrethodenMesec & "_20" & Godina & ".xlsx", NewName:= _
"Y:\AM\20" & Godina & "\INV_" & Godina & "\Inv_mvmt_" & Mesec & "_20" & Godina & ".xlsx", Type:=xlExcelLinks
'
'*****KWH*****
VariableWB.ChangeLink Name:="Y:\AM\20" & Godina & "\KWH_" & Godina & "\KWh_" & Godina & PrethodenMesec & ".xls", NewName:= _
"Y:\AM\20" & Godina & "\KWH_" & Godina & "\KWh_" & Godina & Mesec & ".xls", Type:=xlExcelLinks
'*****Maintenance*****
ActiveWorkbook.ChangeLink Name:="Y:\AM\20" & Godina & "\MNT_" & Godina & "\Maintenance_" & Godina & PrethodenMesec & ".xls", NewName:= _
"Y:\AM\20" & Godina & "\MNT_" & Godina & "\Maintenance_" & Godina & Mesec & ".xls", Type:=xlExcelLinks
'*****MIS*****
ActiveWorkbook.ChangeLink Name:="Y:\AM\20" & Godina & "\MIS_" & Godina & "\MIS" & Godina & PrethodenMesec & ".xlsx", NewName:= _
"Y:\AM\20" & Godina & "\MIS_" & Godina & "\MIS" & Godina & Mesec & ".xlsx", Type:=xlExcelLinks
'*****MIS MINUS EDNA GODINA*****
ActiveWorkbook.ChangeLink Name:="Y:\AM\20" & PrethodnaGodina & "\MIS_" & PrethodnaGodina & "\MIS" & PrethodnaGodina & PrethodenMesec & ".xlsx", NewName:= _
"Y:\AM\20" & PrethodnaGodina & "\MIS_" & PrethodnaGodina & "\MIS" & PrethodnaGodina & Mesec & ".xlsx", Type:=xlExcelLinks
'*****MR*****
ActiveWorkbook.ChangeLink Name:="Y:\AM\20" & Godina & "\MR_" & Godina & "\MR" & Godina & PrethodenMesec & ".xls", NewName:= _
"Y:\AM\20" & Godina & "\MR_" & Godina & "\MR" & Godina & Mesec & ".xls", Type:=xlExcelLinks
'*****PDATA*****
ActiveWorkbook.ChangeLink Name:="Y:\AM\20" & Godina & "\TECH_" & Godina & "\PData_" & Godina & PrethodenMesec & "_v.xls", NewName:= _
"Y:\AM\20" & Godina & "\TECH_" & Godina & "\PData_" & Godina & Mesec & "_v.xls", Type:=xlExcelLinks
'*****SALES*****
ActiveWorkbook.ChangeLink Name:="Y:\AM\20" & Godina & "\SALES_" & Godina & "\SALES" & Godina & PrethodenMesec & ".xls", NewName:= _
"Y:\AM\20" & Godina & "\SALES_" & Godina & "\SALES" & Godina & Mesec & ".xls", Type:=xlExcelLinks
'*****RM Stocks*****
ActiveWorkbook.ChangeLink Name:="Y:\AM\20" & Godina & "\TECH_" & Godina & "\RM_STOCKS_" & Godina & PrethodenMesec & "_v.xls", NewName:= _
"Y:\AM\20" & Godina & "\TECH_" & Godina & "\RM_STOCKS_" & Godina & Mesec & "_v.xls", Type:=xlExcelLinks
'VariableWB.Save
'VariableWB.Close
Application.DisplayAlerts = True
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub