想要用VB6编写Excel代码吗

想要用VB6编写Excel代码吗,vb6,Vb6,我想将excel文件Sheet1的A列的值转换为变量字符串,更改其值后,我想将其粘贴到同一excel文件的另一张Sheet2的A列中。以下是您需要执行的操作: 首先,通过访问以下内容,确保在VB6引用中引用EXCEL: 项目>引用>Microsoft Excel XX对象库 其中XX是安装在PC上的Office版本 Dim objEX As New Excel.Application objEX.Visible = True ' Optional if you want to see wha

我想将excel文件Sheet1的A列的值转换为变量字符串,更改其值后,我想将其粘贴到同一excel文件的另一张Sheet2的A列中。

以下是您需要执行的操作:

首先,通过访问以下内容,确保在VB6引用中引用EXCEL: 项目>引用>Microsoft Excel XX对象库

其中XX是安装在PC上的Office版本

Dim objEX As New Excel.Application

objEX.Visible = True 
' Optional if you want to see what is going on in EXCEL 
' while your code is being executed.


    objEX.Workbooks.Open "C:\My Files\Filename.xls"    
        'Make sure you put the right path of the excel workbook you want to open

With objEX
    'If you know the name of the sheet you want to read from 
    ' then use this code
    .Sheets("FIRST_Sheet_Name_Here").Activate

    'Otherwise, you may only know that the sheet is 
    ' physically the first sheet in that workbook, then use this code:
    .Sheets(1).Activate

    Dim myValue As Double

    myValue = .Range("A1").Value  
   ' Change A1 to whatever Cell you want to read from the sheet

    'Now we will do something with the value that we read and 
    ' then will save it back to EXCEL in sheet 2 and cell B2 for example
    myValue = Val(myValue) + 1000

    .Sheets("SECOND_Sheet_Name_Here").Activate   
    'if you know that name of the second sheet


    .Sheets(2).Activate                          
    'if you don't know the name, but know the location

    .Range("B2").Value = myValue                 
    ' This will write the variable to the location B2 in sheet 2



    .ActiveWorkbook.Save                         
    'Saves the changes you have done


    .ActiveWorkbook.Close                        
    'Close the workbooks but keeps Excel application open


    .Quit                                        
    'Quits excel instance and releases the process from task manager

End With

    Set objEX = Nothing            
   'Garbage Collection and making sure memory is released to other processes.

想要是一回事,行动是另一回事。到目前为止你写了什么?这似乎是一个问题的副本。这是一个副本-我回答了一个完整的解释和项目的例子。