vba 如何使用VB.net在Excel中选择单元格A3?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6708047/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to select a cell A3 in Excel using VB.net?
提问by Yugal Jindle
I want to select the Cell A3 using VB.net..
我想使用 VB.net 选择单元格 A3 ..
I tried doing this by:
我尝试通过以下方式执行此操作:
sheet.Range("A3:A3").Select()
But this gives an exception = Select method of Range Class Failed !
但这给出了一个例外=范围类的选择方法失败!
What is the problem and how to do it ?
有什么问题以及如何解决?
Please help.. I am waiting for the reply !
请帮忙..我在等回复!
采纳答案by jonsca
This program works for me in VB.NET, I agree with rajah9, check the other aspects.
这个程序在 VB.NET 中对我有用,我同意rajah9,检查其他方面。
Imports Excel = Microsoft.Office.Interop.Excel
Public Class Form1
Dim oExcel As Object
Dim oBook As Object
Dim oSheet As Object
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
oExcel = CreateObject("Excel.Application")
oBook = oExcel.Workbooks.Add()
oSheet = oBook.Worksheets(1)
oSheet.Range("A3").Select()
oExcel.ActiveCell.Value = "Put text here"
oBook.SaveAs("C:\Path\testinterop.xlsx")
oExcel.Quit()
End Sub
End Class
(based on, and drawn in part from, examples here)
(基于并部分取自此处的示例)
回答by Jim Counts
Assuming you meant Excel VBA try this:
假设你的意思是 Excel VBA 试试这个:
sheet.Range("A3").Select
You can just specify the cell if all you want is one cell.
如果您只需要一个单元格,则可以指定单元格。