excel vb 把提取出来的一串字符,写入到单元格里
MsgBoxChartObjects(1).Chart.SeriesCollection(1).Formula这段代码可以显示图表的数据源,但是数据太长容易写错,想要让它...
MsgBox ChartObjects(1).Chart.SeriesCollection(1).Formula
这段代码可以显示图表的数据源,但是数据太长容易写错,想要让它直接放到单元格里面,以便复制,请教!谢谢! 展开
这段代码可以显示图表的数据源,但是数据太长容易写错,想要让它直接放到单元格里面,以便复制,请教!谢谢! 展开
2个回答
展开全部
xcel在C盘根目录下生成一个名为 Test.xls 的空文件,然后启动VB6
首先在工程中引用 Microsoft Excel 11.0 Object Library
力求简单,显示数据我仅仅用了3个Textbox控件来完成!
代码如下:
Dim objExcelFile As Excel.Application
Dim objWorkBook As Excel.Workbook
Dim objImportSheet As Excel.Worksheet
Dim inx As Integer
Private Sub Command1_Click()
objImportSheet.Cells(1, inx).Value = Text1.Text
inx = inx + 1
If inx > 3 Then inx = 1
End Sub
Private Sub Command2_Click()
objImportSheet.SaveAs "c:\test.xls"
Text2.Text = GetRowData(1, 1)
Text3.Text = GetRowData(1, 2)
Text4.Text = GetRowData(1, 3)
End Sub
Private Sub Form_Load()
Set objExcelFile = New Excel.Application
objExcelFile.DisplayAlerts = False
Set objWorkBook = objExcelFile.Workbooks.Open("c:\test.xls")
Set objImportSheet = objWorkBook.Sheets(1)
inx = 1
End Sub
Private Sub Form_Unload(Cancel As Integer)
On Error Resume Next
objImportSheet.SaveAs "c:\test.xls"
objExcelFile.Quit
Set objWorkBook = Nothing
Set objImportSheet = Nothing
Set objExcelFile = Nothing
End Sub
Function GetRowData(sRow As Integer, sCow As Integer) As String
GetRowData = Trim$(objImportSheet.Cells(sRow, sCow).Value)
End Function
首先在工程中引用 Microsoft Excel 11.0 Object Library
力求简单,显示数据我仅仅用了3个Textbox控件来完成!
代码如下:
Dim objExcelFile As Excel.Application
Dim objWorkBook As Excel.Workbook
Dim objImportSheet As Excel.Worksheet
Dim inx As Integer
Private Sub Command1_Click()
objImportSheet.Cells(1, inx).Value = Text1.Text
inx = inx + 1
If inx > 3 Then inx = 1
End Sub
Private Sub Command2_Click()
objImportSheet.SaveAs "c:\test.xls"
Text2.Text = GetRowData(1, 1)
Text3.Text = GetRowData(1, 2)
Text4.Text = GetRowData(1, 3)
End Sub
Private Sub Form_Load()
Set objExcelFile = New Excel.Application
objExcelFile.DisplayAlerts = False
Set objWorkBook = objExcelFile.Workbooks.Open("c:\test.xls")
Set objImportSheet = objWorkBook.Sheets(1)
inx = 1
End Sub
Private Sub Form_Unload(Cancel As Integer)
On Error Resume Next
objImportSheet.SaveAs "c:\test.xls"
objExcelFile.Quit
Set objWorkBook = Nothing
Set objImportSheet = Nothing
Set objExcelFile = Nothing
End Sub
Function GetRowData(sRow As Integer, sCow As Integer) As String
GetRowData = Trim$(objImportSheet.Cells(sRow, sCow).Value)
End Function
追问
看不懂……
展开全部
cells(1,1)=ChartObjects(1).Chart.SeriesCollection(1).Formula
追问
这个不成功,出错
追答
试一下下面的语句
Dim ChartSource As String
ChartSource = ActiveSheet.ChartObjects(1).Chart.SeriesCollection(1).Formula
Cells(1, 1) = "'" & ChartSource
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询