我不熟悉编码并在MS Excel中使用VBA将值从一个工作簿移动到另一个工作簿,运行计算,然后执行自动过滤器,将相关数据重新带回原始工作簿。
我遇到了一个让我难过的问题。我的代码在我的计算机上完美运行,但在服务器位置无效,或在本地保存在另一台机器上。文件路径不是问题 - 此代码的一部分打开了必要的电子表格,并且该部分代码工作正常。一旦代码指示软件使一个命名范围中的值与另一个工作簿上的相同命名范围相同,就会显示错误9。我尝试了一些不同的事情但无济于事,并且在这个网站上找不到任何有用的东西。
请停下来!我也很乐意受到批评,以便我可以从中学到更多。如果您有关于我如何清理它的建议请告诉我!
Sub TIMECALCULATION()
'START TOOL DIMENSION OUTPUT FROM ITEM WORKSHEET TO MACHINE MASTER FOR SETUP & CYLE TIME CALCULATION
Application.Calculation = xlManual
Application.ScreenUpdating = False
Workbooks.Open Filename:=ThisWorkbook.Path & "\Machine Master.xlsm", ReadOnly:=True
ActiveWindow.Visible = False
Application.EnableEvents = False
Dim wb1 As Workbook, wb2 As Workbook
Dim wb As Workbook
Dim Ret
Set wb1 = Workbooks("MACHINE MASTER")
Set wb2 = Application.ThisWorkbook
Dim ws5 As Worksheet, ws6 As Worksheet
Set ws5 = wb1.Worksheets("INPUT")
Set ws6 = wb2.Worksheets("CALCULATION PAGE")
With ws5
.Range("SERIES").Value = ws6.Range("SERIES").Value
.Range("FLUTES").Value = ws6.Range("FLUTES").Value
.Range("CTRCUT").Value = ws6.Range("CTRCUT").Value
.Range("PLUNGING").Value = ws6.Range("PLUNGING").Value
.Range("SERIESREVISION").Value = ws6.Range("SERIESREVISION").Value
.Range("BLANKLEN").Value = ws6.Range("BLANKLEN").Value
.Range("BLANKDIA").Value = ws6.Range("BLANKDIA").Value
.Range("BLANKFIN").Value = ws6.Range("BLANKFIN").Value
.Range("COOLTHRUTYPE").Value = ws6.Range("COOLTHRUTYPE").Value
.Range("ITEMNUM").Value = ws6.Range("ITEMNUM").Value
.Range("ITEMREVISION").Value = ws6.Range("ITEMREVISION").Value
.Range("ROTATION").Value = ws6.Range("ROTATION").Value
.Range("FLUTEDIRECTION").Value = ws6.Range("FLUTEDIRECTION").Value
.Range("PEELGRINDLEN").Value = ws6.Range("PEELGRINDLEN").Value
.Range("PEELUCUTLEN").Value = ws6.Range("PEELUCUTLEN").Value
.Range("CUTDIA").Value = ws6.Range("CUTDIA").Value
If ws6.Range("CUTDIATOL").Offset(0, -1).Value = "±" Then
.Range("CUTDIATOL").Value = ws6.Range("CUTDIATOL").Value * 2
Else
.Range("CUTDIATOL").Value = ws6.Range("CUTDIATOL").Value
End If
.Range("SHKDIA").Value = ws6.Range("SHKDIA").Value
If ws6.Range("SHKDIATOL").Offset(0, -1).Value = "±" Then
.Range("SHKDIATOL").Value = ws6.Range("SHKDIATOL").Value * 2
Else
.Range("SHKDIATOL").Value = ws6.Range("SHKDIATOL").Value
End If
.Range("LOC").Value = ws6.Range("LOC").Value
If ws6.Range("LOCTOL").Offset(0, -1).Value = "±" Then
.Range("LOCTOL").Value = ws6.Range("LOCTOL").Value * 2
Else
.Range("LOCTOL").Value = ws6.Range("LOCTOL").Value
End If
.Range("OAL").Value = ws6.Range("OAL").Value
If ws6.Range("OALTOL").Offset(0, -1).Value = "±" Then
.Range("OALTOL").Value = ws6.Range("OALTOL").Value * 2
Else
.Range("OALTOL").Value = ws6.Range("OALTOL").Value
End If
.Range("ENDWORK").Value = ws6.Range("ENDWORK").Value
.Range("ENDCORNER").Value = ws6.Range("ENDCORNER").Value
If .Range("ENDCORNER").Value = "BALL NOSE" Then
.Range("ENDCORNER").Value = "RADIUS"
End If
.Range("FLTBTM").Value = ws6.Range("FLTBTM").Value
.Range("RADSIZE").Value = ws6.Range("RADSIZE").Value
If ws6.Range("RADSIZETOL").Offset(0, -1).Value = "±" Then
.Range("RADSIZETOL").Value = ws6.Range("RADSIZETOL").Value * 2
Else
.Range("RADSIZETOL").Value = ws6.Range("RADSIZETOL").Value
End If
.Range("CHAMLEN").Value = ws6.Range("CHAMLEN").Value
If ws6.Range("CHAMLENTOL").Offset(0, -1).Value = "±" Then
.Range("CHAMLENTOL").Value = ws6.Range("CHAMLENTOL").Value * 2
Else
.Range("CHAMLENTOL").Value = ws6.Range("CHAMLENTOL").Value
End If
.Range("CHAMANG").Value = ws6.Range("CHAMANG").Value
If ws6.Range("CHAMANGTOL").Offset(0, -1).Value = "±" Then
.Range("CHAMANGTOL").Value = ws6.Range("CHAMANGTOL").Value * 2
Else
.Range("CHAMANGTOL").Value = ws6.Range("CHAMANGTOL").Value
End If
.Range("POINTANG").Value = ws6.Range("POINTANG").Value
If ws6.Range("POINTANGTOL").Offset(0, -1).Value = "±" Then
.Range("POINTANGTOL").Value = ws6.Range("POINTANGTOL").Value * 2
Else
.Range("POINTANGTOL").Value = ws6.Range("POINTANGTOL").Value
End If
.Range("UCUT").Value = ws6.Range("UCUT").Value
.Range("REACH").Value = ws6.Range("REACH").Value
If ws6.Range("REACHTOL").Offset(0, -1).Value = "±" Then
.Range("REACHTOL").Value = ws6.Range("REACHTOL").Value * 2
Else
.Range("REACHTOL").Value = ws6.Range("REACHTOL").Value
End If
.Range("NECKDIA1").Value = ws6.Range("NECKDIA1").Value
If ws6.Range("NECKDIA1TOL").Offset(0, -1).Value = "±" Then
.Range("NECKDIA1TOL").Value = ws6.Range("NECKDIA1TOL").Value * 2
Else
.Range("NECKDIA1TOL").Value = ws6.Range("NECKDIA1TOL").Value
End If
.Range("NECKDIA2").Value = ws6.Range("NECKDIA2").Value
If ws6.Range("NECKDIA2TOL").Offset(0, -1).Value = "±" Then
.Range("NECKDIA2TOL").Value = ws6.Range("NECKDIA2TOL").Value * 2
Else
.Range("NECKDIA2TOL").Value = ws6.Range("NECKDIA2TOL").Value
End If
.Range("BACKCLEARREQ").Value = ws6.Range("BACKCLEARREQ").Value
.Range("BACKSIDECUT").Value = ws6.Range("BACKSIDECUT").Value
.Range("EDGEPREP").Value = ws6.Range("EDGEPREP").Value
.Range("DBLEND").Value = ws6.Range("DBLEND").Value
.Range("COATING").Value = ws6.Range("COATING").Value
.Range("FLAT").Value = ws6.Range("FLAT").Value
.Range("NUM1FLATLENTYPE").Value = ws6.Range("NUM1FLATLENTYPE").Value
.Range("REDSHK").Value = ws6.Range("REDSHK").Value
.Range("REDSHKLEN").Value = ws6.Range("REDSHKLEN").Value
.Range("REDSHKLENTOL").Value = ws6.Range("REDSHKLENTOL").Value
.Range("TAPER").Value = ws6.Range("TAPER").Value
.Range("TAPERDEFMETHOD").Value = ws6.Range("TAPERDEFMETHOD").Value
.Range("TAPERANG").Value = ws6.Range("TAPERANG").Value
If ws6.Range("TAPERANGTOL").Offset(0, -1).Value = "±" Then
.Range("TAPERANGTOL").Value = ws6.Range("TAPERANGTOL").Value * 2
Else
.Range("TAPERANGTOL").Value = ws6.Range("TAPERANGTOL").Value
End If
.Range("TAPERCUTTOSHANK").Value = ws6.Range("TAPERCUTTOSHANK").Value
.Range("UNEQINDX").Value = ws6.Range("UNEQINDX").Value
.Range("VARHLX").Value = ws6.Range("VARHLX").Value
.Range("UNEQHLX").Value = ws6.Range("UNEQHLX").Value
.Range("VARRAKE").Value = ws6.Range("VARRAKE").Value
.Range("FLTPOL").Value = ws6.Range("FLTPOL").Value
.Range("HELIX").Value = ws6.Range("HELIX").Value
.Range("FLUTELEN").Value = ws6.Range("FLUTELEN").Value
If ws6.Range("FLUTELENTOL").Offset(0, -1).Value = "±" Then
.Range("FLUTELENTOL").Value = ws6.Range("FLUTELENTOL").Value * 2
Else
.Range("FLUTELENTOL").Value = ws6.Range("FLUTELENTOL").Value
End If
.Range("COREDIAF").Value = ws6.Range("COREDIAF").Value
.Range("PASS2").Value = ws6.Range("PASS2").Value
.Range("PASS2COREDIAF").Value = ws6.Range("PASS2COREDIAF").Value
.Range("PASS3").Value = ws6.Range("PASS3").Value
.Range("PASS3COREDIAF").Value = ws6.Range("PASS3COREDIAF").Value
.Range("FLT1LEADF").Value = ws6.Range("FLT1LEADF").Value
.Range("EUROFLT").Value = ws6.Range("EUROFLT").Value
.Range("EUROFLTHELIX").Value = ws6.Range("EUROFLTHELIX").Value
.Range("EUROFLTCOREDIAF").Value = ws6.Range("EUROFLTCOREDIAF").Value
.Range("EUROFLTCORETPR").Value = ws6.Range("EUROFLTCORETPR").Value
.Range("SKIFLT").Value = ws6.Range("SKIFLT").Value
.Range("KLAND").Value = ws6.Range("KLAND").Value
.Range("COREDIAB").Value = ws6.Range("COREDIAB").Value
.Range("PASS2COREDIAB").Value = ws6.Range("PASS2COREDIAB").Value
.Range("PASS3COREDIAB").Value = ws6.Range("PASS3COREDIAB").Value
.Range("ODRELTYPE").Value = ws6.Range("ODRELTYPE").Value
.Range("CIRLAND").Value = ws6.Range("CIRLAND").Value
.Range("FLTTYPE").Value = ws6.Range("FLTTYPE").Value
.Range("ODPOL").Value = ws6.Range("ODPOL").Value
.Range("ECCLANDWIDTH").Value = ws6.Range("ECCLANDWIDTH").Value
If ws6.Range("ECCLANDWIDTHTOL").Offset(0, -1).Value = "±" Then
.Range("ECCLANDWIDTHTOL").Value = ws6.Range("ECCLANDWIDTHTOL").Value * 2
Else
.Range("ECCLANDWIDTHTOL").Value = ws6.Range("ECCLANDWIDTHTOL").Value
End If
.Range("PRIRLFWIDTH").Value = ws6.Range("PRIRLFWIDTH").Value
If ws6.Range("PRIRLFWIDTHTOL").Offset(0, -1).Value = "±" Then
.Range("PRIRLFWIDTHTOL").Value = ws6.Range("PRIRLFWIDTHTOL").Value * 2
Else
.Range("PRIRLFWIDTHTOL").Value = ws6.Range("PRIRLFWIDTHTOL").Value
End If
.Range("SECRELIEF").Value = ws6.Range("SECRELIEF").Value
.Range("SECRLFWIDTH").Value = ws6.Range("SECRLFWIDTH").Value
If ws6.Range("SECRLFWIDTHTOL").Offset(0, -1).Value = "±" Then
.Range("SECRLFWIDTHTOL").Value = ws6.Range("SECRLFWIDTHTOL").Value * 2
Else
.Range("SECRLFWIDTHTOL").Value = ws6.Range("SECRLFWIDTHTOL").Value
End If
.Range("ECCLANDWIDTHB").Value = ws6.Range("ECCLANDWIDTHB").Value
If ws6.Range("ECCLANDWIDTHBTOL").Offset(0, -1).Value = "±" Then
.Range("ECCLANDWIDTHBTOL").Value = ws6.Range("ECCLANDWIDTHBTOL").Value * 2
Else
.Range("ECCLANDWIDTHBTOL").Value = ws6.Range("ECCLANDWIDTHBTOL").Value
End If
.Range("PRIRLFWIDTHB").Value = ws6.Range("PRIRLFWIDTHB").Value
If ws6.Range("PRIRLFWIDTHBTOL").Offset(0, -1).Value = "±" Then
.Range("PRIRLFWIDTHBTOL").Value = ws6.Range("PRIRLFWIDTHBTOL").Value * 2
Else
.Range("PRIRLFWIDTHBTOL").Value = ws6.Range("PRIRLFWIDTHBTOL").Value
End If
.Range("SECRLFWIDTHB").Value = ws6.Range("SECRLFWIDTHB").Value
If ws6.Range("SECRLFWIDTHBTOL").Offset(0, -1).Value = "±" Then
.Range("SECRLFWIDTHBTOL").Value = ws6.Range("SECRLFWIDTHBTOL").Value * 2
Else
.Range("SECRLFWIDTHBTOL").Value = ws6.Range("SECRLFWIDTHBTOL").Value
End If
.Range("EGPREP").Value = ws6.Range("EGPREP").Value
.Range("EDGEPREPSHAPE").Value = ws6.Range("EDGEPREPSHAPE").Value
.Range("EDGEPREPSIZE").Value = ws6.Range("EDGEPREPSIZE").Value
.Range("GRIOW").Value = ws6.Range("GRIOW").Value
.Range("GASHRAD").Value = ws6.Range("GASHRAD").Value
.Range("GASHWHLANG").Value = ws6.Range("GASHWHLANG").Value
.Range("GASHANG").Value = ws6.Range("GASHANG").Value
.Range("GASHWALKANG").Value = ws6.Range("GASHWALKANG").Value
.Range("SECENDRELIEF").Value = ws6.Range("SECENDRELIEF").Value
.Range("TERTIARY").Value = ws6.Range("TERTIARY").Value
.Range("WIPERFLAT").Value = ws6.Range("WIPERFLAT").Value
.Range("WIPERFLATWIDTH").Value = ws6.Range("WIPERFLATWIDTH").Value
If ws6.Range("WIPERFLATWIDTHTOL").Offset(0, -1).Value = "±" Then
.Range("WIPERFLATWIDTHTOL").Value = ws6.Range("WIPERFLATWIDTHTOL").Value * 2
Else
.Range("WIPERFLATWIDTHTOL").Value = ws6.Range("WIPERFLATWIDTHTOL").Value
End If
.Range("TIPNOTCH").Value = ws6.Range("TIPNOTCH").Value
.Range("NOTCHDEPTH").Value = ws6.Range("NOTCHDEPTH").Value
.Range("NOTCHWIDTH").Value = ws6.Range("NOTCHWIDTH").Value
.Range("RAKESURF").Value = ws6.Range("RADROUNDING").Value
.Range("SGASH").Value = ws6.Range("SGASH").Value
.Range("CHISELDIA").Value = ws6.Range("CHISELDIA").Value
.Range("CHIPBRKR").Value = ws6.Range("CHIPBRKR").Value
.Range("CHIPBRKRSHAPE").Value = ws6.Range("CHIPBRKRSHAPE").Value
.Range("CHIPBRKRDEPTH").Value = ws6.Range("CHIPBRKRDEPTH").Value
.Range("CHIPBRKRPITCH").Value = ws6.Range("CHIPBRKRPITCH").Value
.Range("CHIPBRKRSTART").Value = ws6.Range("CHIPBRKRSTART").Value
.Range("CHIPBRKRRAD").Value = ws6.Range("CHIPBRKRRAD").Value
.Range("COBBPITCH").Value = ws6.Range("COBBPITCH").Value
.Range("COBBSTART").Value = ws6.Range("COBBSTART").Value
.Range("ROUGHSPIN").Value = ws6.Range("ROUGHSPIN").Value
.Range("SPINTOFINAL").Value = ws6.Range("SPINTOFINAL").Value
.Range("SPUNPOLISH").Value = ws6.Range("SPUNPOLISH").Value
.Range("SPUNDIA").Value = ws6.Range("SPUNDIA").Value
.Range("SPUNLEN").Value = ws6.Range("SPUNLEN").Value
.Range("LEADOUTANG").Value = ws6.Range("LEADOUTANG").Value
.Range("SPINTAPER").Value = ws6.Range("SPINTAPER").Value
.Range("TAPERSPINTOSHANK").Value = ws6.Range("TAPERSPINTOSHANK").Value
.Range("SPUNTAPERENDSHARP").Value = ws6.Range("SPUNTAPERENDSHARP").Value
.Range("SPUNDIA2").Value = ws6.Range("SPUNDIA2").Value
.Range("TAPERLEADOUTLEN").Value = ws6.Range("TAPERLEADOUTLEN").Value
.Range("SPUNTAPERLEN").Value = ws6.Range("SPUNTAPERLEN").Value
.Range("SPUNTAPERANG").Value = ws6.Range("SPUNTAPERANG").Value
.Range("SPINCHAM").Value = ws6.Range("SPINCHAM").Value
.Range("SPUNCHAMDIA1").Value = ws6.Range("SPUNCHAMDIA1").Value
.Range("SPUNCHAMDIA2").Value = ws6.Range("SPUNCHAMDIA2").Value
.Range("SPUNCHAMANG").Value = ws6.Range("SPUNCHAMANG").Value
.Range("SPUNCHAMLEN1").Value = ws6.Range("SPUNCHAMLEN1").Value
.Range("SPUNCHAMLEN2").Value = ws6.Range("SPUNCHAMLEN2").Value
.Range("TOUCHANDTAKE").Value = ws6.Range("TOUCHANDTAKE").Value
.Range("SPINPOINT").Value = ws6.Range("SPINPOINT").Value
.Range("SPUNPOINTTIPDIA").Value = ws6.Range("SPUNPOINTTIPDIA").Value
.Range("SPUNPOINTOD").Value = ws6.Range("SPUNPOINTOD").Value
.Range("SPUNPOINTANG").Value = ws6.Range("SPUNPOINTANG").Value
.Range("SPUNPOINTLEN").Value = ws6.Range("SPUNPOINTLEN").Value
.Range("CNCFIRSTPLUNGE").Value = ws6.Range("CNCFIRSTPLUNGE").Value
.Range("SPINUCUT").Value = ws6.Range("SPINUCUT").Value
.Range("FULLPREUCUT").Value = ws6.Range("FULLPREUCUT").Value
.Range("PRECNCMANDISH").Value = ws6.Range("PRECNCMANDISH").Value
.Range("BKSDCLNUP").Value = ws6.Range("BKSDCLNUP").Value
.Range("PREUCUTCNCLOC").Value = ws6.Range("PREUCUTCNCLOC").Value
.Range("SPUNCUTDIALEN").Value = ws6.Range("SPUNCUTDIALEN").Value
.Range("BACKSIDEANG").Value = ws6.Range("BACKSIDEANG").Value
.Range("SPUNNECKF").Value = ws6.Range("SPUNNECKF").Value
.Range("SPUNNECKB").Value = ws6.Range("SPUNNECKB").Value
.Range("SPUNREACH").Value = ws6.Range("SPUNREACH").Value
.Range("CUT").Value = ws6.Range("CUT").Value
.Range("CUTWHEN").Value = ws6.Range("CUTWHEN").Value
.Range("GRINDOAL").Value = ws6.Range("GRINDOAL").Value
.Range("OALGRINDPURPOSE").Value = ws6.Range("OALGRINDPURPOSE").Value
.Range("NUM1FLATLEN").Value = ws6.Range("NUM1FLATLEN").Value
.Range("WELDONCOUNT").Value = ws6.Range("WELDONCOUNT").Value
End With
'END DATA OUTPUT TO MACHINE MASTER
'CLEAR ANY EXISITING ROUTING DATA IN THE CURRENT WORKBOOK
wb2.Sheets("ROUTING").Range("2:1048576").Delete
Application.Calculate
'START DATA INPUT FROM MACHINE MASTER
'THE FOLLOWING CODE AUTOFILTERS THE FULL ROUTINGS ON TABS 1, 2, & 3 IN THE MACHINE MASTER WORKBOOK AND PASTES THAT INFORMATION IN THIS ITEM WORKBOOK ON THE ROUTING WORKSHEET.
'Dim wb2 As Workbook
Dim ws1 As Worksheet, ws2 As Worksheet, ws3 As Worksheet, ws4 As Worksheet
Dim copyFrom As Range
Dim lRow As Long
Dim strSearch As String
Set ws1 = wb1.Worksheets("1")
Set ws2 = wb1.Worksheets("2")
Set ws3 = wb1.Worksheets("3")
strSearch = "Y"
With ws1
.AutoFilterMode = False
lRow = .Range("A" & .Rows.Count).End(xlUp).Row
With .Range("A1:A" & lRow)
.AutoFilter Field:=1, Criteria1:="=*" & strSearch & "*"
Set copyFrom = .Offset(1, 0).SpecialCells(xlCellTypeVisible).EntireRow
End With
.AutoFilterMode = False
End With
Set wb2 = ThisWorkbook
Set ws4 = wb2.Worksheets("ROUTING")
With ws4
'lRow = 2
lRow = .Range("B" & .Rows.Count).End(xlUp).Row + 1
copyFrom.Copy .Rows(lRow)
End With
With ws2
.AutoFilterMode = False
lRow = .Range("A" & .Rows.Count).End(xlUp).Row
With .Range("A1:A" & lRow)
.AutoFilter Field:=1, Criteria1:="=*" & strSearch & "*"
Set copyFrom = .Offset(1, 0).SpecialCells(xlCellTypeVisible).EntireRow
End With
.AutoFilterMode = False
End With
Set wb2 = ThisWorkbook
Set ws4 = wb2.Worksheets("ROUTING")
With ws4
'lRow = 2
lRow = .Range("B" & .Rows.Count).End(xlUp).Row + 1
copyFrom.Copy .Rows(lRow)
End With
With ws3
.AutoFilterMode = False
lRow = .Range("A" & .Rows.Count).End(xlUp).Row
With .Range("A1:A" & lRow)
.AutoFilter Field:=1, Criteria1:="=*" & strSearch & "*"
Set copyFrom = .Offset(1, 0).SpecialCells(xlCellTypeVisible).EntireRow
End With
.AutoFilterMode = False
End With
Set wb2 = ThisWorkbook
Set ws4 = wb2.Worksheets("ROUTING")
With ws4
lRow = .Range("B" & .Rows.Count).End(xlUp).Row + 1
copyFrom.Copy .Rows(lRow)
End With
wb1.Close SaveChanges:=False
Application.Calculation = xlAutomatic
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub
答案 0 :(得分:1)
仔细检查ThisWorkbook.Path是否使用debug.print
返回预期路径。在VBA编辑器中首先转到View =>立即窗口,然后在您的计算机和不使用的计算机上运行debug.print ThisWorkbook.Path
。
切割工具也很棒。切削刀具的ISO13399标准可能会使这些数据在未来更容易维护。我知道某些大型供应商正在尝试将您已构建的功能出售给此工作表(需要大量资金)。
答案 1 :(得分:1)
@Rory - 答案是将文件路径更改为Workbooks(“Machine Master.xlsm”)
谢谢,谢谢,谢谢大家的建议和时间!我期待成为这个社区的一员,并尽我所能为其他人做出贡献。祝周末愉快!
-J