|
本帖最后由 xfpxfp168 于 2016-7-19 17:34 编辑
对EXCEL工作表编制了宏命令
excel 执行该宏时 系统提示EXCEL已停止工作,退出时EXCEL程序崩溃
重新安装OFFICE EXCEL仍无法解决。
请各位老师看看:是否宏命令存在错误,拟或存在其他问题。谢谢。(工作表请见附件)
Sub 按钮1_Click()
'
' 按钮1_Click Macro
'
'统计I列合同号的个数
Dim H$
H = Application.WorksheetFunction.CountA(Sheet1.Range("I2:I13"))
If H = 0 Then
MsgBox "请在I2:I13单元格输入 合同编号 "
Exit Sub
End If
Application.ScreenUpdating = False
Application.DisplayAlerts = False
'将I列合同号循环赋值给B3单元格
Dim XXX$
Dim CCC As Integer
For CCC = 2 To H + 1
XXX = Cells(CCC, 9)
Cells(3, 2) = XXX
'更新链接,重新计算
ActiveWorkbook.UpdateLinks = xlUpdateLinksAlways
ActiveWorkbook.RefreshAll
Application.Calculate
'将文件按规定名称存于本表所在路径
Dim qqq$
qqq = [d1]
Dim wb As Workbook
Set wb = ActiveWorkbook
wb.Worksheets(1).Copy
ActiveWorkbook.SaveAs ThisWorkbook.Path & "\发货通知单" & qqq & ".xlsx"
'选择性粘贴为数据
Cells.Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
'保存后关闭
ActiveWorkbook.Save
ActiveWorkbook.Close
Next CCC
Application.DisplayAlerts = True
Application.ScreenUpdating = True
MsgBox "备份完毕"
End Sub
|
|