VB操作Excel进行的合并单元格中碰到问题,高手请进
当我第一次运行时,一切都正常;但是当再次运行时,弹出错误框,
"Method 'Range' of object '_Global' failed"
不知道是什么原因?望赐教!
以下是源程序:
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Sub MergeCell(CellRange As String)
Range(CellRange).Select
Selection.MergeCells = True
Selection.HorizontalAlignment = xlCenter
Selection.VerticalAlignment = xlCenter
End Sub
Private Sub Command1_Click()
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets(1)
MergeCell "A1:A5"
xlApp.Visible = True
Set xlApp = Nothing
End Sub