在excel里列宽设置的问题。该不是bug吧? 你用的什么版本?我这边没问题,window2000+office2000 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 把这段代码拷到你机器上试试,是好的,但如果把注释去掉,就不行了,列宽不对了.我发觉是.MergeCells = True的问题Private Sub Command1_Click()riqi = 31Dim xlApp As Excel.ApplicationDim xlBook As Excel.WorkbookDim xlSheet As Excel.WorksheetSet xlApp = CreateObject("Excel.Application")xlApp.Visible = TrueSet xlBook = xlApp.Workbooks.AddSet xlSheet = xlBook.Worksheets(1)xlSheet.Cells(3, 1) = "工号"xlSheet.Cells(3, 2) = "姓名"For i = 1 To riqixlSheet.Cells(3, i + 2) = i Next i xlSheet.Cells(3, riqi + 3) = "夜" xlSheet.Cells(3, riqi + 4) = "中" xlSheet.Cells(3, riqi + 5) = "工" xlSheet.Cells(3, riqi + 6) = "病" xlSheet.Cells(3, riqi + 7) = "事"With xlApp '.Range("A1:AG2").Select ' With .Selection ' .HorizontalAlignment = xlCenter ' .MergeCells = True ' End With ' With .Selection.Font ' .Name = "华文行楷" ' .Size = 24 ' .Strikethrough = False ' .Superscript = False ' .Subscript = False ' .OutlineFont = False ' .Shadow = False ' .Underline = xlUnderlineStyleNone ' .ColorIndex = xlAutomatic ' End With '缩小字体填充 Range("A4:AO17").Select With Selection .ShrinkToFit = True End With Columns("A:A").Select Range("A3").Activate Selection.ColumnWidth = 3.5 Columns("B:B").Select Range("B3").Activate Selection.ColumnWidth = 5.5 Columns("C:AG").Select Range("C3").Activate Selection.ColumnWidth = 2 ActiveWindow.LargeScroll ToRight:=1 ActiveWindow.SmallScroll ToRight:=-5 Columns("AH:AO").Select Selection.ColumnWidth = 3 End With xlApp.Visible = True '显示表格Set xlApp = Nothing '交还控制给ExcelEnd Sub 把这段代码拷到你机器上试试,是好的,但如果把注释去掉,就不行了,列宽不对了.我发觉是.MergeCells = True的问题Private Sub Command1_Click()riqi = 31Dim xlApp As Excel.ApplicationDim xlBook As Excel.WorkbookDim xlSheet As Excel.WorksheetSet xlApp = CreateObject("Excel.Application")xlApp.Visible = TrueSet xlBook = xlApp.Workbooks.AddSet xlSheet = xlBook.Worksheets(1)xlSheet.Cells(3, 1) = "工号"xlSheet.Cells(3, 2) = "姓名"For i = 1 To riqixlSheet.Cells(3, i + 2) = i Next i xlSheet.Cells(3, riqi + 3) = "夜" xlSheet.Cells(3, riqi + 4) = "中" xlSheet.Cells(3, riqi + 5) = "工" xlSheet.Cells(3, riqi + 6) = "病" xlSheet.Cells(3, riqi + 7) = "事"With xlApp '.Range("A1:AG2").Select ' With .Selection ' .HorizontalAlignment = xlCenter ' .MergeCells = True ' End With ' With .Selection.Font ' .Name = "华文行楷" ' .Size = 24 ' .Strikethrough = False ' .Superscript = False ' .Subscript = False ' .OutlineFont = False ' .Shadow = False ' .Underline = xlUnderlineStyleNone ' .ColorIndex = xlAutomatic ' End With '缩小字体填充 Range("A4:AO17").Select With Selection .ShrinkToFit = True End With Columns("A:A").Select Range("A3").Activate Selection.ColumnWidth = 3.5 Columns("B:B").Select Range("B3").Activate Selection.ColumnWidth = 5.5 Columns("C:AG").Select Range("C3").Activate Selection.ColumnWidth = 2 ActiveWindow.LargeScroll ToRight:=1 ActiveWindow.SmallScroll ToRight:=-5 Columns("AH:AO").Select Selection.ColumnWidth = 3 End With xlApp.Visible = True '显示表格Set xlApp = Nothing '交还控制给ExcelEnd Sub 这个代码为什么错啦? VB如何实现URL反unicode编码 使用什么函数可以取到 SSH/TELNET, DOS上显示的文字? 用activebar的高手请进来,给分手不软! 如何解决程序运行 招人:vb+财务 将文件存入指定的文件夹,如果有重复的名字则将当前文件更名? 如何获得控件名 毕业设计问题--- vb 中的datagrid与textbox连接 百分相送 vb 连接数据库 请问怎么捕捉Delete按键 救救我,不要让羊入虎口!
riqi = 31
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
Set xlBook = xlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets(1)
xlSheet.Cells(3, 1) = "工号"
xlSheet.Cells(3, 2) = "姓名"
For i = 1 To riqi
xlSheet.Cells(3, i + 2) = i
Next i
xlSheet.Cells(3, riqi + 3) = "夜"
xlSheet.Cells(3, riqi + 4) = "中"
xlSheet.Cells(3, riqi + 5) = "工"
xlSheet.Cells(3, riqi + 6) = "病"
xlSheet.Cells(3, riqi + 7) = "事"
With xlApp
'.Range("A1:AG2").Select
' With .Selection
' .HorizontalAlignment = xlCenter
' .MergeCells = True
' End With
' With .Selection.Font
' .Name = "华文行楷"
' .Size = 24
' .Strikethrough = False
' .Superscript = False
' .Subscript = False
' .OutlineFont = False
' .Shadow = False
' .Underline = xlUnderlineStyleNone
' .ColorIndex = xlAutomatic
' End With
'缩小字体填充
Range("A4:AO17").Select
With Selection
.ShrinkToFit = True
End With
Columns("A:A").Select
Range("A3").Activate
Selection.ColumnWidth = 3.5
Columns("B:B").Select
Range("B3").Activate
Selection.ColumnWidth = 5.5
Columns("C:AG").Select
Range("C3").Activate
Selection.ColumnWidth = 2
ActiveWindow.LargeScroll ToRight:=1
ActiveWindow.SmallScroll ToRight:=-5
Columns("AH:AO").Select
Selection.ColumnWidth = 3
End With
xlApp.Visible = True '显示表格
Set xlApp = Nothing '交还控制给Excel
End Sub
riqi = 31
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
Set xlBook = xlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets(1)
xlSheet.Cells(3, 1) = "工号"
xlSheet.Cells(3, 2) = "姓名"
For i = 1 To riqi
xlSheet.Cells(3, i + 2) = i
Next i
xlSheet.Cells(3, riqi + 3) = "夜"
xlSheet.Cells(3, riqi + 4) = "中"
xlSheet.Cells(3, riqi + 5) = "工"
xlSheet.Cells(3, riqi + 6) = "病"
xlSheet.Cells(3, riqi + 7) = "事"
With xlApp
'.Range("A1:AG2").Select
' With .Selection
' .HorizontalAlignment = xlCenter
' .MergeCells = True
' End With
' With .Selection.Font
' .Name = "华文行楷"
' .Size = 24
' .Strikethrough = False
' .Superscript = False
' .Subscript = False
' .OutlineFont = False
' .Shadow = False
' .Underline = xlUnderlineStyleNone
' .ColorIndex = xlAutomatic
' End With
'缩小字体填充
Range("A4:AO17").Select
With Selection
.ShrinkToFit = True
End With
Columns("A:A").Select
Range("A3").Activate
Selection.ColumnWidth = 3.5
Columns("B:B").Select
Range("B3").Activate
Selection.ColumnWidth = 5.5
Columns("C:AG").Select
Range("C3").Activate
Selection.ColumnWidth = 2
ActiveWindow.LargeScroll ToRight:=1
ActiveWindow.SmallScroll ToRight:=-5
Columns("AH:AO").Select
Selection.ColumnWidth = 3
End With
xlApp.Visible = True '显示表格
Set xlApp = Nothing '交还控制给Excel
End Sub