当前位置:编程学习 > VB >>

求救~VB导出excel的时候,第一次是可以的,第二次就没有边框和图了

补充代码: Private Sub Command1_Click() Dim myChart As ChartObject Dim xlapp As Excel.Application Set xlapp = New Excel.Application Dim xlBook As Excel.Workbook Dim xlSheet As Excel.Worksheet On Error Resume Next DoEvents xlapp.SheetsInNewWorkbook = 2 Set xlBook = xlapp.Workbooks.Add xlBook.Sheets(1).Name = "产品及主要技术指标表" xlBook.Sheets(2).Name = "累计净现金流量与净现值曲线图" xlBook.Worksheets(1).Select With Form5.MSFlexGrid3 For a05 = 0 To .Rows - 1 For a06 = 0 To .Cols - 1 DoEvents xlBook.Sheets(1).Cells(5 + a05, a06 + 2) = "'" & .TextMatrix(a05, a06) Next a06 Next a05 End With xlapp.DisplayAlerts = False Range(Cells(3, 2), Cells(4, Form5.MSFlexGrid3.Cols + 1)).Select Selection.Font.FontStyle = "Bold" Selection.Font.Size = 14 Selection.Value = "产品及主要技术指标表" Selection.Merge Range(Cells(5, 2), Cells(Form5.MSFlexGrid3.Rows + 4, Form5.MSFlexGrid3.Cols + 1)).Font.Size = 14 xlapp.Selection.Cells.EntireColumn.AutoFit '自动调整列宽 Range(Cells(3, 2), Cells(Form5.MSFlexGrid3.Rows + 4, Form5.MSFlexGrid3.Cols + 1)).Borders.LineStyle = xlContinuous For x03 = 2 To Form5.MSFlexGrid3.Cols + 1 For y03 = 6 To Form5.MSFlexGrid3.Rows + 4 Cells(y03, x03) = Cells(y03, x03) * 1 Next y03 Next x03 Range(Cells(3, 2), Cells(Form5.MSFlexGrid3.Rows + 4, Form5.MSFlexGrid3.Cols + 1)).HorizontalAlignment = xlCente
补充:xlBook.Worksheets(2).Select
 Charts.Add
    ActiveChart.ChartType = xlXYScatterSmoothNoMarkers
    ActiveChart.SeriesCollection.NewSeries
    ActiveChart.SeriesCollection.NewSeries
    ActiveChart.SeriesCollection(1).Values = str_a
    ActiveChart.SeriesCollection(1).Name = "=""净现值"""
    ActiveChart.SeriesCollection(2).Values = str_b
    ActiveChart.SeriesCollection(2).Name = "=""净现金流量"""
    ActiveChart.Location Where:=xlLocationAsObject, Name:="净现金流量与净现值曲线图"
     With ActiveChart
        .HasTitle = True
        .ChartTitle.Characters.Text = "净现金流量与净现值曲线图"
        .Axes(xlCategory, xlPrimary).HasTitle = True
        .Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "计算期年份"
        .Axes(xlValue, xlPrimary).HasTitle = True
        .Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "数值份额(万元)"
    End With
xlBook.Close (True) 
 xlapp.Quit 
 Set xlSheet = Nothing
  Set xlBook = Nothing
  Set xlapp = Nothing
答案:先录一个宏做导出试试,如果成功再改宏,如果不成功检查导出操作
其他:这么多代码,头疼啊,不如发电子表格一张啊

上一个:VBA怎么学习?
下一个:VB杀全部进程代码

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,