我在這裏看到了同樣的問題,但無法解決...請幫助。 海先生目前我在一個項目中把所有的excel宏都以2003格式轉換到2007.我面臨的問題是對象_global失敗的方法範圍 請給我一個解決方案。對象_global的方法範圍在命名範圍內失敗
請查看代碼...有範圍(「Phasewt」)沒有更新.... 沒有在這本書的工作已命名的範圍正在更新,隨處可見其示值誤差1004: 蔭現在使用Office 2007。
Private Sub FormatRowsAndSum(ByVal TotRows As Integer, StartRow As Integer)
Dim rngFormat As Range
'adds formatting
If TotRows > 2 Then
Set rngFormat = Range(Cells(StartRow + 2, 2), Cells(TotRows + StartRow + 1, 8))
'Range("B11:H11").Select
Range(Cells(StartRow + 1, 2), Cells(StartRow + 1, 8)).Select
Selection.Copy
rngFormat.Select
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
'adds formula
Set rngFormat = Range(Cells(StartRow + 2, 11), Cells(TotRows + StartRow, 12))
'Range("K11:L11").Select
Range(Cells(StartRow + 1, 11), Cells(StartRow + 1, 12)).Select
Selection.Copy
rngFormat.Select
Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
End If
ActiveSheet.PageSetup.FitToPagesWide = 1
Cells(TotRows + StartRow + 1, 2) = "TOTALS"
Cells(TotRows + StartRow + 1, 2).Font.Bold = True
Cells(TotRows + StartRow + 1, 2).RowHeight = 20
Range(Cells(TotRows + StartRow + 1, 2), Cells(TotRows + StartRow + 1, 8)).Select
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
End With
'writes total weight
With Cells(TotRows + StartRow + 1, 6)
.Value = "=SUM(K" & StartRow & ":K" & TotRows + StartRow & ")"
.Font.Bold = True
.NumberFormat = "#,##0.00"
End With
If Range("ReleaseTo") <> "STR" Then
Range("PhaseWt") = Cells(TotRows + StartRow + 1, 6) ' writes total wt in cover page
End If
'writes total cladding Area
With Cells(TotRows + StartRow + 1, 7)
.Value = "=SUM(L" & StartRow & ":L" & TotRows + StartRow & ")"
.Font.Bold = True
.NumberFormat = "#,##0.00"
End With
If Cells(TotRows + StartRow + 1, 7) > 0 Then
If Range("ReleaseTo") <> "STR" Then
Range("PhaseArea") = Cells(TotRows + StartRow + 1, 7) ' writes total Area in cover page
End If
End If
'writes total quantity
With Cells(TotRows + StartRow + 1, 3)
.Value = "=SUM(C" & StartRow & ":C" & TotRows + StartRow & ")"
.Font.Bold = True
.NumberFormat = "#,##0"
End With
Range("B4").Select
End Sub
感謝您的關注。
歡迎堆棧溢出!您可以先[參觀](http://stackoverflow.com/tour)並學習[如何提出一個好問題](http://stackoverflow.com/help/how-to-ask)並創建一個[最小,完整和可驗證](http://stackoverflow.com/help/mcve)示例。這使我們更容易幫助你。 –