如何激活特定的工作簿和特定工作表? [英] How do i activate a specific workbook and a specific sheet?

查看:2052
本文介绍了如何激活特定的工作簿和特定工作表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从当前工作簿中激活我的其他工作簿?我有一个目前的工作簿与dumb.xls,另一个工作簿名称为Tire.xls.I已从dumb.xls使用 worksbooks.open filename:=文件的名称打开了Tire.xls 。它已经开放,但问题是我无法使其工作。



如果我说单元格(2, 24).value = 24 将这些值放在dumb.xls的单元格中,但我希望它可以完成一个Tire.xls。



activesheet.cells(2,24).value = 24 将它们放在Tire.xls上。但是如何用名称激活工作簿?我需要打开3到4个excel工作簿并执行操作?我如何激活特定的工作簿



我在google上找到了这个代码

  activeworkbook.worksheet(sheetname)。激活'但不工作
windows(sheetname)。激活'在google上的人建议不要使用
pre>

它没有被激活。我不知道如何使它工作。任何人都可以告诉我如何激活特定的工作簿和其他工作簿的特定工作表?



示例:我有niko.xls和niko_2.xls作为工作簿打开dumb.xls工作簿完全3个工作簿,我必须激活niko_2.xls工作簿的第2页。我如何做?有人可以用这个例子来解释我的语法吗?谢谢你提前

解决方案

你不需要激活工作表(你会获得巨大的表现,其实)。由于您正在声明该表单的对象,当您调用以wb开头的方法时。您正在选择该对象。例如,您可以在工作簿之间跳转,而不需要激活以下任何操作:

  Sub Test()

Dim wb1 As Excel.Workbook
设置wb1 = Workbooks.Open(C:\Documents and Settings\xxxx\Desktop\test1.xls)
Dim wb2 As Excel.Workbook
设置wb2 = Workbooks.Open(C:\Documents and Settings\xxxx\Desktop\test2.xls)

wb1.Sheets(Sheet1)。单元格单元格(1,1).Value = 24
wb1.Sheets(Sheet1)。单元格(2,1) .Value = 54

End Sub


How do I activate my Other workbook from the Current workbook? I have a current workbook with dumb.xls and The other workbook name as Tire.xls.I have opened the Tire.xls from the dumb.xls using worksbooks.open filename:= "name of the file".Its getting open but The problem is Im unable to make it work.

If I say cells(2,24).value=24 puts these value in the cell of dumb.xls but I want it to be done one Tire.xls.

activesheet.cells(2,24).value=24 puts these on Tire.xls. But how do i activate the Workbook with the name ? I need to open 3 to 4 excel workbooks And perform the operation? How do I activate the specific workbook

I have found this code on google

     activeworkbook.worksheet("sheetname").activate  ' but not working
     windows("sheetname").activate ' people on google suggested not to use

Its not getting activated. I dont know how to make it work. Can anyone tell me How do i activate a specific workbook and a specific sheet of the other workbook ?

Example: I have niko.xls and niko_2.xls opened as workbooks from the dumb.xls workbook so totally 3 workbooks and I have to activate the 2nd sheet of niko_2.xls workbook.How do I make it? Can anyone explain me the syntax with these example? Thank you in advance

解决方案

You do not need to activate the sheet (you'll take a huge performance hit for doing so, actually). Since you are declaring an object for the sheet, when you call the method starting with "wb." you are selecting that object. For example, you can jump in between workbooks without activating anything like here:

Sub Test()

Dim wb1 As Excel.Workbook
Set wb1 = Workbooks.Open("C:\Documents and Settings\xxxx\Desktop\test1.xls")
Dim wb2 As Excel.Workbook
Set wb2 = Workbooks.Open("C:\Documents and Settings\xxxx\Desktop\test2.xls")

wb1.Sheets("Sheet1").Cells(1, 1).Value = 24
wb2.Sheets("Sheet1").Cells(1, 1).Value = 24
wb1.Sheets("Sheet1").Cells(2, 1).Value = 54

End Sub

这篇关于如何激活特定的工作簿和特定工作表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆