将未命名的工作簿链接到VBA中的变量 [英] Linking un-named workbook to variable in VBA

查看:48
本文介绍了将未命名的工作簿链接到VBA中的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个宏,它将宏从Excel中的一个工作簿复制并粘贴到另一个工作簿中.数据所在的工作簿与该宏是同一工作簿.我已经使VBA创建了一个新工作簿以粘贴数据.如何将VBA刚创建的新工作簿分配给变量.

I am writing a macro that will copy and paste information form one workbook into another workbook in excel 2010. The workbook that the data is in is the same workbook as the macro. I have made VBA create a new workbook to paste the data in. How do I assign the new workbook that VBA has just created to a variable.

感谢任何帮助

推荐答案

您还没有完全提到创建工作簿的方式,但是可以在同一对象中设置对新的 Workbook 对象的引用创建它的语句.

You haven't mentioned exactly how you create the workbook, but you can set a reference to the new Workbook object in the same statement that creates it.

示例:

Option Explicit

Sub AddWorkbook()

    Dim oWb As Workbook

    Set oWb = Workbooks.Add

    'Do something with the new workbook
    Debug.Print oWb.FullName

    Set oWb = Nothing
End Sub

这篇关于将未命名的工作簿链接到VBA中的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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