程序執行時出錯,請幫忙看看

M_Judy0 2008-11-07 10:38:00

程序執行時提示執行階段錯誤1004,EXCEL無法取用檔案......
Sub Shipping()
Dim MyPath As String
Sheets("shipdata").Select
MyPath = ThisWorkbook.Path & "\shipdata\"
Sheets("shipdata").Copy
ActiveWorkbook.SaveAs MyPath & "shipdata_GSL_" & _
Year(Range("D1")) & "_" & Month(Range("D1")) & "_" & Day(Range("D1")) & ".xls"

With Range("D1")
.Copy
.PasteSpecial Paste:=xlPasteValues
End With
ActiveWorkbook.Save
ActiveWorkbook.Close True

Sheets("shipdata").Select
With Range(Range("B3:D3"), Range("B3:D3").End(xlDown))
.ClearContents
.Borders(xlDiagonalDown).LineStyle = xlNone
.Borders(xlDiagonalUp).LineStyle = xlNone
.Borders(xlEdgeLeft).LineStyle = xlNone
.Borders(xlEdgeTop).LineStyle = xlNone
.Borders(xlEdgeBottom).LineStyle = xlNone
.Borders(xlEdgeRight).LineStyle = xlNone
.Borders(xlInsideVertical).LineStyle = xlNone
.Borders(xlInsideHorizontal).LineStyle = xlNone
End With
Range("B3").Select
End Sub
...全文
112 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
M_Judy0 2008-11-07
  • 打赏
  • 举报
回复
我已解決,謝謝!
haiyangshao 2008-11-07
  • 打赏
  • 举报
回复
按F8键, 单步调试一下, 就会发现错误在哪里了.
后面的代码:
With Range("D1")
.Copy
.PasteSpecial Paste:=xlPasteValues
End With
ActiveWorkbook.Save
ActiveWorkbook.Close True

Sheets("shipdata").Select
With Range(Range("B3:D3"), Range("B3:D3").End(xlDown))
.ClearContents
.Borders(xlDiagonalDown).LineStyle = xlNone
.Borders(xlDiagonalUp).LineStyle = xlNone
.Borders(xlEdgeLeft).LineStyle = xlNone
.Borders(xlEdgeTop).LineStyle = xlNone
.Borders(xlEdgeBottom).LineStyle = xlNone
.Borders(xlEdgeRight).LineStyle = xlNone
.Borders(xlInsideVertical).LineStyle = xlNone
.Borders(xlInsideHorizontal).LineStyle = xlNone
End With
Range("B3").Select

应该都不会发生阶段性错误
主要检查前面的几句代码
Sheets("shipdata").Select
MyPath = ThisWorkbook.Path & "\shipdata\"
Sheets("shipdata").Copy
ActiveWorkbook.SaveAs MyPath & "shipdata_GSL_" & _
Year(Range("D1")) & "_" & Month(Range("D1")) & "_" & Day(Range("D1")) & ".xls"

看看文件路径是否存在, 或者当前用户有没有访问权限

5,172

社区成员

发帖
与我相关
我的任务
社区描述
其他开发语言 Office开发/ VBA
社区管理员
  • Office开发/ VBA社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧