With xlSheet.Application
.Range("C4:F6").Merge '合并单元格
.Range("C4") = "我"
.Range("C4").Font.Bold = True '设字体为粗体
End With
xlSheet.Cells.HorizontalAlignment = xlCenter '设置上下居中
xlSheet.Cells.VerticalAlignment = xlCenter
xlSheet.Cells.NumberFormatLocal = "@"
以上代码End With以下的不起作用,请教老师,怎么样改才能达到整个工作表xlSheet数据上下左右居中的结果?
.Range("C4:F6").Merge '合并单元格
.Range("C4") = "我"
.Range("C4").Font.Bold = True '设字体为粗体
End With
xlSheet.Cells.HorizontalAlignment = xlCenter '设置上下居中
xlSheet.Cells.VerticalAlignment = xlCenter
xlSheet.Cells.NumberFormatLocal = "@"
以上代码End With以下的不起作用,请教老师,怎么样改才能达到整个工作表xlSheet数据上下左右居中的结果?
xlSheet.Cells.HorizontalAlignment = xlCenter
xlSheet.Cells.VerticalAlignment = xlCenter
xlSheet.Cells.NumberFormatLocal = "@"
Public wb As Excel.Workbook
Public sh As Excel.Worksheet
Private Sub Command3_Click()
Set ex = CreateObject("Excel.Application")
Set wb = ex.Workbooks.Open("C:\A.XLS") '你的文件
Set sh = wb.Sheets(1) sh.Cells.HorizontalAlignment = xlCenter
sh.Cells.VerticalAlignment = xlBottom
sh.Cells.WrapText = False
sh.Cells.Orientation = 0
sh.Cells.AddIndent = False
sh.Cells.IndentLevel = 0
sh.Cells.ShrinkToFit = False
sh.Cells.ReadingOrder = xlContext
sh.Cells.MergeCells = False ex.Visible = True
'wb.Close SaveChanges:=True '直接关闭不保存
'ex.Quit
Set ex = Nothing
Set wb = Nothing
Set sh = Nothing
End Sub
Public xlBook As Excel.Workbook
Public xlSheet As Excel.Worksheet
Private Sub Command1_Click()
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open(App.Path & "\A.xls") '你的文件
Set xlSheet = xlBook.Sheets(1)
xlSheet.Cells.HorizontalAlignment = xlCenter
xlSheet.Cells.VerticalAlignment = xlBottom
xlSheet.Cells.WrapText = False
xlSheet.Cells.Orientation = 0
xlSheet.Cells.AddIndent = False
xlSheet.Cells.IndentLevel = 0
xlSheet.Cells.ShrinkToFit = False
xlSheet.Cells.ReadingOrder = xlContext
xlSheet.Cells.MergeCells = False
xlApp.Visible = True
'wb.Close SaveChanges:=True '直接关闭不保存
'ex.Quit
Set xlApp = Nothing
Set xlBook = Nothing
Set sh = Nothing
End Sub
结果:开不了文件
实时错误'-2147417851(80010105)'
自动化错误
Set xlBook = xlApp.Workbooks.Open(App.Path & "\A.xls") '你的文件
变色
其实我原来程序的前部分也是:
Public xlApp As Excel.Application
Public xlBook As Excel.Workbook
Public xlSheet As Excel.Worksheet
Private Sub Command1_Click()
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open(App.Path & "\A.xls") '你的文件
Set xlSheet = xlBook.Sheets(1)
运行并没有什么出错问题,只是后设置单元格部分语句没起作用,现在连设置单元格的语句运行不到就出错了.真是见鬼了!
Set ex = CreateObject("Excel.Application")
Set wb = ex.Workbooks.Open(App.Path & "\A.xls") '你的文件
Set sh = wb.Sheets(1) '第一个工作表
sh.Rows("4:4").Select
ex.Selection.Insert Shift:=xlDown
Set sh = wb.Sheets(2) '第二个工作表
wb.Sheets("Sheet2").Select
sh.Columns("B:B").Select
ex.Selection.Insert Shift:=xlToRight
ex.Visible = True
'wb.Close SaveChanges:=True '直接关闭不保存
'ex.Quit
Set ex = Nothing
Set wb = Nothing
Set sh = Nothing
End Sub
测试没有问题 应该是你的文件没有放在程序目录下