ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Referencing an opened Workbook (https://www.excelbanter.com/excel-programming/332159-referencing-opened-workbook.html)

BerkshireGuy[_2_]

Referencing an opened Workbook
 
Hello all,

In an Access 2000 module, I have a routine that creates a new excel
workbook (so its called Book1) and copies rows from Access to the Excel
workbook.

Then in a subroutine, I want to do some other stuff with the OPENED
workbook.

What would be the proper way of referencing an OPENED Excel workbook?

Thanks,
Brian


bac

Referencing an opened Workbook
 
When you open the new workbook you should save the workbook's name into a
variable:

new_woorkbook = activeworkbook.name

then you can always get to that workbook with:

workbooks(new_workbook).activate

please rate this post below

thanx
bac



"BerkshireGuy" wrote:

Hello all,

In an Access 2000 module, I have a routine that creates a new excel
workbook (so its called Book1) and copies rows from Access to the Excel
workbook.

Then in a subroutine, I want to do some other stuff with the OPENED
workbook.

What would be the proper way of referencing an OPENED Excel workbook?

Thanks,
Brian



keepITcool

Referencing an opened Workbook
 

better to use a workbook object variable.

use a module level variable:

dim mWkb as Excel.Workbook

sub ProcA()
set mWkb=workbooks.open("c:\book.xls")
end sub

sub ProcB()
if not mWkb is nothing
then mWkb.close
end if
end sub

OR (better?) use arguments..

sub ProcC()
dim wkb as Excel.Workbook
set wkb=workbooks.open("c:\book.xls")
call ProcD(wkb)
end sub

sub ProcD(wkb as Excel.Workbook)
if not wkb is nothing
then wkb.close
end if
end sub



--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam


BAC wrote :

When you open the new workbook you should save the workbook's name
into a variable:

new_woorkbook = activeworkbook.name

then you can always get to that workbook with:

workbooks(new_workbook).activate

please rate this post below

thanx
bac



"BerkshireGuy" wrote:

Hello all,

In an Access 2000 module, I have a routine that creates a new excel
workbook (so its called Book1) and copies rows from Access to the
Excel workbook.

Then in a subroutine, I want to do some other stuff with the OPENED
workbook.

What would be the proper way of referencing an OPENED Excel
workbook?

Thanks,
Brian




All times are GMT +1. The time now is 11:39 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com